php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63825 php dose not follow the operator precedence
Submitted: 2012-12-21 06:10 UTC Modified: 2012-12-21 11:07 UTC
From: rssidea at qq dot com Assigned:
Status: Not a bug Package: *Compile Issues
PHP Version: 5.3.20 OS: all
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
46 - 2 = ?
Subscribe to this entry?

 
 [2012-12-21 06:10 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-21 06:30 UTC] rssidea at qq dot com
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 :)
 [2012-12-21 06:30 UTC] rssidea at qq dot com
-Status: Open +Status: Closed
 [2012-12-21 11:07 UTC] johannes@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 14:01:30 2024 UTC