BEHAVIOR OF USE OF INTERACTION IN A SECRET LINE WITH A CALCULATION IS NOT DEFINED!
The compiler may generate other code that you expect.
A simple answer from my teacher:
NEVER USE A RECORD / DECREE OPERATOR IN ONE CALCULATED LINE!
This behavior is undefined - computers calculate in a different order than people do.
OK:
$d = $i++; $i++; for ($i = 0; $i < 5; $i++)
MAY BE A PROBLEM (you may not read it correctly):
$d = $array[$i++];
There will be a problem:
$d = $i++ + 5 - --$k;
EDIT:
I wrote the same code in C ++. Check the assembler code and the result, as I said: Mathematics with growth is not logic for people, but you cannot say that someone implemented it incorrectly.
As someone posted in a comment:
line #* EIO op fetch ext return operands ------------------------------------------------------------------------------------- 2 0 E > ASSIGN !0, 1 3 1 POST_INC ~2 !0 2 ADD ~3 !0, ~2 3 ECHO ~3 16 4 > RETURN 1 //$a = 1; //echo ($a+$a++); line #* EIO op fetch ext return operands ------------------------------------------------------------------------------------- 2 0 E > ASSIGN !0, 1 3 1 ADD ~2 !0, !0 2 POST_INC ~3 !0 3 ADD ~4 ~2, ~3 4 ECHO ~4 5 > RETURN 1 //$a = 1; //echo ($a+$a+$a++);
Translation into human language:
$a = 1; echo ($a + $a++); // After changing to 'computer logic' (ASM): $c = 1; // for increment operation $b = $a; // keep value 'before' add +1 operation $a += $c; // add +1 operation $d = $a + $b; // calculate value for 'echo' echo $d; // print result
JerzySBG
source share