Bug #63599 [NEW]: Operators : == is useless

From: Date: Sun, 25 Nov 2012 17:20:39 +0000
Subject: Bug #63599 [NEW]: Operators : == is useless
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-174933@lists.php.net to get a copy of this message
From: michel dot lecorsier at orange dot fr Operating system: Ubuntu PHP version: 5.4.9 Package: *Programming Data Structures Bug Type: Bug Bug description:Operators : == is useless Description: ------------ == is useless. It’s not transitive. "foo" == TRUE, and "foo" == 0… but, of course, TRUE != 0. == converts to numbers when possible (123 == "123foo"… although "123" != "123foo"), which means it converts to floats when possible. So large hex strings (like, say, password hashes) may occasionally compare true when they’re not. Even JavaScript doesn’t do this. For the same reason, "6" == " 6", "4.2" == "4.20", and "133" == "0133". But note that 133 != 0133, because 0133 is octal. But "0x10" == "16" and "1e3" == "1000"! === compares values and type… except with objects, where === is only true if both operands are actually the same object! For objects, == compares both value (of every attribute) and type, which is what === does for every other type. What. Test script: --------------- <?php $toto = "Foo"; if ($toto == "foo") { echo 'yes'; exit; } else { echo 'fail'; exit; } -- Edit bug report at https://bugs.php.net/bug.php?id=63599&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=63599&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=63599&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=63599&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=63599&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=63599&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=63599&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=63599&r=needscript Try newer version: https://bugs.php.net/fix.php?id=63599&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=63599&r=support Expected behavior: https://bugs.php.net/fix.php?id=63599&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=63599&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=63599&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=63599&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63599&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=63599&r=dst IIS Stability: https://bugs.php.net/fix.php?id=63599&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=63599&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=63599&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=63599&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=63599&r=mysqlcfg

« previous php.bugs (#174933) next »