The php manual states that:
$a = 1; echo ++$a + $a++;
ambiguous in its grammar, but it seems extremely clear to me. ++ $ a and $ a ++ are evaluated first, from left to right, so ++ $ a increases and then returns 2, and $ a ++ returns 2, and then increases. The sum of 2 + 2 is 4, so it will be echo 4. However, the PHP manual says very clearly that it can print 4 or 5.
Does the php specification indicate that operations will be performed from left to right?
Even if this does not guarantee that the operations will be performed from left to right, in this case, will it not return 4 independently?
Edit: I re-read the page, and she stated that it is determined by each specific operator. + has the lowest priority and evaluates from left to right, so it seems that my previous assumption was correct. I still do not understand.
php operator-precedence interpreter grammar
nnythm
source share