ID:               49019
 User updated by:  michaeldnelson dot mdn at gmail dot com
 Reported By:      michaeldnelson dot mdn at gmail dot com
 Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: freebsd
 PHP Version:      5.2.10
 New Comment:

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


Previous Comments:
------------------------------------------------------------------------

[2009-07-22 21:25:12] j...@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: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] j...@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

Reply via email to