I've been struggling to understand why this returns 252448 instead of 251248.
<?php $a = 4; echo ++$a * $a++ . $a += $a . $a *= 4; ?> My thinking is: ++$a * $a++ gives 25 (5*5), after that we have a incremented to 6 and added to itself, so we have 12, and 12 multiplied by 4 so we get 48.
And:
<?php $a = 4; echo ++$a * $a++ . $a *= 4 . $a += $a; ?> returns 254944 which is even more confusing. I thought that this would return 252448 according to similar logic.
Can anybody explain to me why that is?
++$a * $a++can be 25 (5*5) or 24 (6*4). Here it is possible, that++$aor$a++is executed first. This is a general issue in all languages. Search for "sequence point" for more details.