php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49019 order of operations is not valid for assignment in all cases
Submitted: 2009-07-22 17:10 UTC Modified: 2009-07-22 21:53 UTC
From: michaeldnelson dot mdn at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.10 OS: freebsd
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: michaeldnelson dot mdn at gmail dot com
New email:
PHP Version: OS:

 

 [2009-07-22 17:10 UTC] michaeldnelson dot mdn at gmail dot com
Description:
------------
It appears = has a higher precedence than || in some situations which is contrary to the manual.  This exception is not noted as far as I can tell.

var_dump(!$test = false || !$test2 = false);
is being interpreted like this
var_dump(!$test = (false || !$test2 = false));
instead of like this
var_dump((!$test = false) || (!$test2 = false));

If I missed something my apologies.

Thanks,
Michael D. Nelson

Reproduce code:
---------------
---
From manual page: language.operators.precedence
---
var_dump(!$test = false || !$test2 = false);
echo "TEST\n";
var_dump($test);
echo "TEST2\n";
var_dump($test2);

Expected result:
----------------
bool(true)
TEST
bool(false)
TEST2
NULL

Actual result:
--------------
bool(false)
TEST
bool(true)
TEST2
bool(false)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-22 20:15 UTC] jani@php.net
= is associated on right, || is associated on left, so that's exactly 
what your code does.. 
 [2009-07-22 21:00 UTC] michaeldnelson dot mdn at gmail dot com
Thank you for the prompt response at the risk of proving myself more obtuse:
 
I am aware of how = and || are associated it would appear to me that if || is associated on the left and it is associated before any = then (!$test = false || !$test2 = false) should evaluate to true because the left portion of this is just (!$test = false) which  evaluates to true, also (!$test = false || false) evaluates to true if you meant that the false immediately to the left was causing this result this case proves otherwise.
 
It still appears to me that ($!test = false || $!test2 = false) evaluates to false because the leftmost = operator is getting evaluated before the ||.  I apologize for taking more of your time but your terse response didn't assuage my doubts on this particular issue, perhaps if you elaborated. Thanks again.)
 [2009-07-22 21:25 UTC] jani@php.net
You propably also missed the fine print:

"Note: 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 what you get is quite expected. No bug here.
 [2009-07-22 21:53 UTC] michaeldnelson dot mdn at gmail dot com
I read that I assumed
if (!$a = foo()) this note was in reference to the ! operators precedence where $a should be as of yet unassigned.

Thank you for your time.

Michael D. Nelson)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 21:01:32 2025 UTC