php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18535 int to string comparison problem
Submitted: 2002-07-24 06:31 UTC Modified: 2002-07-24 19:44 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: marcin dot smieszek at pointblue dot com dot pl Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.2.1 OS: linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: marcin dot smieszek at pointblue dot com dot pl
New email:
PHP Version: OS:

 

 [2002-07-24 06:31 UTC] marcin dot smieszek at pointblue dot com dot pl
any variable, set, but set to 0 (but not "0") compared with any string always returns true.

try 
-------
if (0=="sth) {echo "problem";}
-------
or sth like this: 
-------
$a=array("blahblah","1",1,"0",0);
foreach ($a as $value)
    {
    if ($value == "aaaa")
	{
	echo "<b>true</b><br>";
	}
    else 
	{
	echo "false<br>";
	}
    }
------


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-24 07:21 UTC] hholzgra@php.net
expected behaviour, use === to compare if you do not want type conversions to happen
 [2002-07-24 07:36 UTC] marcin dot smieszek at pointblue dot com dot pl
:-)
then, shouldn't both (1=="aaa") and (0=="aaa") return the same - false or true?
 [2002-07-24 08:05 UTC] hholzgra@php.net
no

the string gets converted to interger zero before 
comparison when using "==", so ...

using === both would be false
 [2002-07-24 08:14 UTC] marcin dot smieszek at pointblue dot com dot pl
ok, all clear :-)
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 22:00:02 2026 UTC