= += -= etc. operators associativity
Posted: Mon Feb 24, 2003 10:47 am
Hi,
in PHP documentation is written, that operators
= += -= *= /= .= %= &= |= ^= ~= <<= >>=
have associativity LEFT. For example
I expect that $y = $z executes first, result is 3 and than is 3 assigned to $x. (Like in C). But it's RIGHT associativity, don't you think so? LEFT associativity means, that $x = $y is made first and $z is assigned to it's result... What's the result? $x? $y? Temporary variable?
However, it's not mistake in documentation, in PHP source is '=' marked also as LEFT associative.
Can anybody tell me how exactly $x = $y = $z (and $x += $y += $z etc.) works? I know that finally $x and $y have the same value as $z
but what does PHP do with that expression?
Thanks, Pavel.
in PHP documentation is written, that operators
= += -= *= /= .= %= &= |= ^= ~= <<= >>=
have associativity LEFT. For example
Code: Select all
$x = 1;
$y = 2;
$z = 3;
$x = $y = $zHowever, it's not mistake in documentation, in PHP source is '=' marked also as LEFT associative.
Can anybody tell me how exactly $x = $y = $z (and $x += $y += $z etc.) works? I know that finally $x and $y have the same value as $z
Thanks, Pavel.