Bug #18535 Updated: int to string comparison problem
| From: | hholzgra@php.net | Date: | Wed, 24 Jul 2002 12:05:56 +0000 |
| Subject: | Bug #18535 Updated: int to string comparison problem | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-15039@lists.php.net to get a copy of this message | ||
ID: 18535
Updated by: hholzgra@php.net
Reported By: marcin.smieszek@pointblue.com.pl
Status: Bogus
Bug Type: *General Issues
Operating System: linux
PHP Version: 4.2.1
New Comment:
no
the string gets converted to interger zero before
comparison when using "==", so ...
using === both would be false
Previous Comments:
------------------------------------------------------------------------
[2002-07-24 07:36:14] marcin.smieszek@pointblue.com.pl
:-)
then, shouldn't both (1=="aaa") and (0=="aaa") return the same - false
or true?
------------------------------------------------------------------------
[2002-07-24 07:21:31] hholzgra@php.net
expected behaviour, use === to compare if you do not want type
conversions to happen
------------------------------------------------------------------------
[2002-07-24 06:31:17] marcin.smieszek@pointblue.com.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>";
}
}
------
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=18535&edit=1