#49019 [Opn->Bgs]: order of operations is not valid for assignment in all cases
| From: | jani@php.net | Date: | Wed, 22 Jul 2009 21:25:12 +0000 |
| Subject: | #49019 [Opn->Bgs]: order of operations is not valid for assignment in all cases | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-140097@lists.php.net to get a copy of this message | ||
ID: 49019
Updated by: jani@php.net
Reported By: michaeldnelson dot mdn at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: freebsd
PHP Version: 5.2.10
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2009-07-22 21:00:09] 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 20:15:52] jani@php.net
= is associated on right, || is associated on left, so that's exactly
what your code does..
------------------------------------------------------------------------
[2009-07-22 17:10:36] 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)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49019&edit=1