Edit report at http://bugs.php.net/bug.php?id=51422&edit=1
ID: 51422
User updated by: ssiangge at yahoo dot com dot sg
Reported by: ssiangge at yahoo dot com dot sg
Summary: invalid result
-Status: Open
+Status: Closed
Type: Bug
Package: *General Issues
Operating System: Win 7, Ubuntu 9.10
PHP Version: 5.2.13
New Comment:
I found answer from the user manual...
hmmm....
#
If you compare an integer with a string, the string is converted to a
number. If you compare two numerical strings, they are compared as
integers. These rules also apply to the switch statement.
#
<?php
var_dump(0 == "a"); // 0 == 0 -> true
var_dump("1" == "01"); // 1 == 1 -> true
switch ("a") {
case 0:
echo "0";
break;
case "a": // never reached because "a" is already matched with 0
echo "a";
break;
}
?>
Previous Comments:
------------------------------------------------------------------------
[2010-03-29 05:42:58] ssiangge at yahoo dot com dot sg
Description:
------------
When I want test the value(int 0) is or is not match with a
string(string "text"), it return true! By right it should return false.
Then I try on other value, it also return wrong result!
Test script:
---------------
<?php
$question = true;
if ("text" == $question) echo "text == $question => true<br />";
else echo "text == $question => false<br />";
$question = 0;
if ("text" == $question) echo "text == $question => true<br />";
else echo "text == $question => false<br />";
$question = 1;
if ("text" == $question) echo "text == $question => true<br />";
else echo "text == $question => false<br />";
$question = false;
if ("text" == $question) echo "text == $question => true<br />";
else echo "text == $question => false<br />";
?>
Expected result:
----------------
text == 1 => false
text == 0 => false
text == 1 => false
text == => false
Actual result:
--------------
text == 1 => true
text == 0 => true
text == 1 => false
text == => false
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51422&edit=1