From: keithm at aoeex dot com Operating system: Linux PHP version: 5CVS-2004-02-26 (dev) PHP Bug Type: Scripting Engine problem Bug description: Comparison order of operations incorrect
Description: ------------ The order of operation for comparisons seems to be incorrect. The following example script will demonstrate the problem: Reproduce code: --------------- <?php $x=0; while ($x != ($x=5)){ echo "x is not equal to x"; } ?> Expected result: ---------------- The screen should display nothing. I would expect that the $x=5 would execute, and then php would compare $x != $x, which of course would be false, and the loop would run. Actual result: -------------- x is not equal to x the loop is executed and that echo statement is displayed. It seems that php pulls the value of $x, execute the $x=5 statement, and runs the comparison. So for a split second, you in essence have two $x variables. One which has the value of 0, and the other with the value of 5. If you reverse the order of the operands in the condition, then it works as expected: <?php $x=0; //This works fine, nothing is displayed while (($x=5) != $x){ echo "x is not equal to x"; } ?> -- Edit bug report at http://bugs.php.net/?id=27409&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=27409&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=27409&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=27409&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=27409&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=27409&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=27409&r=needscript Try newer version: http://bugs.php.net/fix.php?id=27409&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=27409&r=support Expected behavior: http://bugs.php.net/fix.php?id=27409&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=27409&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=27409&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=27409&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27409&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=27409&r=dst IIS Stability: http://bugs.php.net/fix.php?id=27409&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=27409&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=27409&r=float