Bug #63825 [Csd->Nab]: php dose not follow the operator precedence
| From: | johannes@php.net | Date: | Fri, 21 Dec 2012 11:07:39 +0000 |
| Subject: | Bug #63825 [Csd->Nab]: php dose not follow the operator precedence | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-175524@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63825&edit=1
ID: 63825
Updated by: johannes@php.net
Reported by: rssidea at qq dot com
Summary: php dose not follow the operator precedence
-Status: Closed
+Status: Not a bug
Type: Bug
Package: *Compile Issues
Operating System: all
PHP Version: 5.3.20
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2012-12-21 06:30:50] 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:10:55] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63825&edit=1