#17386 [Opn->Csd]: Associativity of assignment operators listed wrongly
| From: | vrana@php.net | Date: | Mon, 26 Jul 2004 14:51:58 +0000 |
| Subject: | #17386 [Opn->Csd]: Associativity of assignment operators listed wrongly | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969362178@lists.php.net to get a copy of this message | ||
ID: 17386
Updated by: vrana@php.net
Reported By: m dot ford at lmu dot ac dot uk
-Status: Open
+Status: Closed
Bug Type: Documentation problem
PHP Version: 4.1.2
Assigned To: john
New Comment:
The precedence is also already documented by the sentence "Although !
has a higher precedence than =, PHP will still allow expressions
similar to the following: if (!$a = foo()), in which case the output
from foo() is put into $a."
Previous Comments:
------------------------------------------------------------------------
[2003-06-21 13:27:16] moriyoshi@php.net
The document was updated and now describes the assignment operators
have right associativity. However I think the precedence rule is
another issue.
------------------------------------------------------------------------
[2002-11-28 18:49:00] john@php.net
I'll make the change for the associtivity from left to right, but I
don't know if I should just make a note of the example regarding
precedence rules.
Anyone know if its intended behavior, or should this have thrown a
parse error?
John
------------------------------------------------------------------------
[2002-05-23 09:34:04] m dot ford at lmu dot ac dot uk
The operators page at /manual/en/language.operators.php lists the the
assignment operators (=, +=, etc.) as being left associative, but they
must logically be right associative. Left associativity would mean that
this:
$a = $b = 0;
was interpreted as:
($a = $b) =0;
which is clearly nonsensical. Indeed a quick test shows that:
$d = $c += $a += $b += 4;
is interpreted as:
$d = ($c += ($a += ($b += 4)));
which looks like right associativity to me!
(Actually, a little further testing suggests that the assignment
operators need some special annotations, as they don't appear to
strictly obey their stated precedence level. For example, the
statement:
$x = $z + $y = 543;
if interpreted strictly according to the precedence rules should be
equivalent to:
$x = ($z + $y) = 543;
which would be a parse error, but in fact is interpreted as:
$x = $z + ($y = 543);
which may be the "obvious" intention, but had me WTF-ing for a while!!)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=17386&edit=1