Edit report at https://bugs.php.net/bug.php?id=63825&edit=1

 ID:                 63825
 User updated by:    rssidea at qq dot com
 Reported by:        rssidea at qq dot com
 Summary:            php dose not follow the operator precedence
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            *Compile Issues
 Operating System:   all
 PHP Version:        5.3.20
 Block user comment: N
 Private report:     N

 New Comment:

I find a note in documentation:Although = has a lower precedence than most 
other 
operators, PHP will still allow expressions similar to the following: if (!$a = 
foo()), in which case the return value of foo() is put into $a.

so, this is not a bug, but it may be a snare :)


Previous Comments:
------------------------------------------------------------------------
[2012-12-21 06:10:55] rssidea at qq dot com

Description:
------------
By Operator Precedence on 
http://php.net/manual/en/language.operators.precedence.php, logical operator 
'||' 
is higher than assignment operator '=', so the script below should cause a 
syntax 
error. 

Test script:
---------------
$a = $b = 0;
if ($a = 1 || $b = 1) {
    echo $a;
}


Expected result:
----------------
execute as:
if ($a = (1 || $b) = 1) {

output:
syntax error, unexpected '='

Actual result:
--------------
execute as:
if ($a = (1 || ($b = 1))) {

output:
1


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63825&edit=1

Reply via email to