#17386 [Opn->Asn]: Associativity of assignment operators listed wrongly

From: Date: Sun, 11 May 2003 13:39:57 +0000
Subject: #17386 [Opn->Asn]: Associativity of assignment operators listed wrongly
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969353342@lists.php.net to get a copy of this message
ID: 17386 Updated by: moriyoshi@php.net Reported By: m dot ford at lmu dot ac dot uk -Status: Open +Status: Assigned Bug Type: Documentation problem PHP Version: 4.1.2 Assigned To: john Previous Comments: ------------------------------------------------------------------------ [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

« previous php.doc (#969353342) next »