#49637 [Opn->Bgs]: Assigning in an IF statement does not update value for rest of IF

From: Date: Wed, 23 Sep 2009 08:15:50 +0000
Subject: #49637 [Opn->Bgs]: Assigning in an IF statement does not update value for rest of IF
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-142748@lists.php.net to get a copy of this message
ID: 49637 Updated by: rasmus@php.net Reported By: erik at ruigekonijnen dot nl -Status: Open +Status: Bogus Bug Type: Variables related Operating System: Windows XP PHP Version: 5.3.0 New Comment: && has higher precedence than = so it is working as expected and as documented at http://php.net/manual/en/language.operators.precedence.php Previous Comments: ------------------------------------------------------------------------ [2009-09-23 08:01:49] erik at ruigekonijnen dot nl Description: ------------ When you assign a new variable directly into an IF statement, it is not updated if you try to read from it in the same statement. The problem can be supressed by adding an extra set of parentheses, but I don't think that should be neccesary. In the example posted below, this would work just fine: if ( ( $a = 1 ) && $a > 0 ) { Reproduce code: --------------- $a = 0; if ( $a = 1 && $a > 0 ) { echo 'ok'; } else { echo 'wait, what?'; } Expected result: ---------------- ok Actual result: -------------- wait, what? ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49637&edit=1

« previous php.bugs (#142748) next »