Edit report at http://bugs.php.net/bug.php?id=51422&edit=1
ID: 51422 Updated by: [email protected] Reported by: ssiangge at yahoo dot com dot sg Summary: invalid result -Status: Closed +Status: Bogus Type: Bug Package: *General Issues Operating System: Win 7, Ubuntu 9.10 PHP Version: 5.2.13 New Comment: That's what the === operator is for. == will do type conversion. A non-zero non-empty string evaluates to true. This is well-documented at http://php.net/manual/en/language.operators.comparison.php Previous Comments: ------------------------------------------------------------------------ [2010-03-29 05:47:52] ssiangge at yahoo dot com dot sg 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; } ?> ------------------------------------------------------------------------ [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
