#37995 [Bgs]: Operator precedence problem
| From: | tony2001@php.net | Date: | Mon, 03 Jul 2006 08:03:16 +0000 |
| Subject: | #37995 [Bgs]: Operator precedence problem | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-99065@lists.php.net to get a copy of this message | ||
ID: 37995
Updated by: tony2001@php.net
Reported By: nisoi at mail dot ru
Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Linux 2.6.15 / GENTOO
PHP Version: 5.1.4
New Comment:
In any language at this planet the result of your expressions is
undefined.
Not PHP problem.
Previous Comments:
------------------------------------------------------------------------
[2006-07-03 08:00:46] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
Never use both assignments/updates and comparison of the same variable
in a statement.
------------------------------------------------------------------------
[2006-07-03 07:54:58] nisoi at mail dot ru
Description:
------------
Looks like there is the operator precedence problem in 5.1.4 (5.1.2
too). 4.4.2 works fine.
When you try to compare the variable with the result of an assigning a
value to it, both left and right parts are equal.
But when you force the left part to evaluate in some way that does not
change the value, left and right parts become different.
Reproduce code:
---------------
$i = 1;
echo ( ( ($i) == ($i = $i + 1)) ? "BUG - THEY ARE EQUAL" : "OK")."\n";
echo ( ( ($i + 0) == ($i = $i + 1)) ? "BUG - THEY ARE EQUAL" :
"FIX")."\n";
Expected result:
----------------
OK
FIX
Actual result:
--------------
BUG
FIX
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=37995&edit=1