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
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: rssidea at qq dot com
New email:
PHP Version: OS:

 

 [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: Thu Apr 18 17:01:28 2024 UTC