php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49637 Assigning in an IF statement does not update value for rest of IF
Submitted: 2009-09-23 08:01 UTC Modified: 2009-09-23 08:15 UTC
From: erik at ruigekonijnen dot nl Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.3.0 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: erik at ruigekonijnen dot nl
New email:
PHP Version: OS:

 

 [2009-09-23 08:01 UTC] 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?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-23 08:15 UTC] rasmus@php.net
&& has higher precedence than =
so it is working as expected and as documented at http://php.net/manual/en/language.operators.precedence.php


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 13:01:32 2024 UTC