php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37995 Operator precedence problem
Submitted: 2006-07-03 07:54 UTC Modified: 2006-07-03 08:03 UTC
From: nisoi at mail dot ru Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.1.4 OS: Linux 2.6.15 / GENTOO
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nisoi at mail dot ru
New email:
PHP Version: OS:

 

 [2006-07-03 07:54 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-03 08:00 UTC] 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 08:03 UTC] tony2001@php.net
In any language at this planet the result of your expressions is undefined.
Not PHP problem.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Dec 04 03:00:01 2025 UTC