ID: 27409 Updated by: [EMAIL PROTECTED] Reported By: keithm at aoeex dot com -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: Linux PHP Version: 5CVS-2004-02-26 (dev) New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php The engine evaluates the operands in the order they occur in the input, as there is no reason to evaluate the second expression first. [The parentheses don't change that.] The first expression evaluates to 0, the second one to 5. Previous Comments: ------------------------------------------------------------------------ [2004-02-26 19:29:49] keithm at aoeex dot com 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 this bug report at http://bugs.php.net/?id=27409&edit=1