#17386 [Opn]: Associativity of assignment operators listed wrongly
| From: | john@php.net | Date: | Fri, 29 Nov 2002 00:49:01 +0000 |
| Subject: | #17386 [Opn]: Associativity of assignment operators listed wrongly | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969350001@lists.php.net to get a copy of this message | ||
ID: 17386
Updated by: john@php.net
Reported By: m.ford@lmu.ac.uk
Status: Open
Bug Type: Documentation problem
PHP Version: 4.1.2
Assigned To: john
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2002-05-23 09:34:04] m.ford@lmu.ac.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