Inspired by the issue of pre / post-increment . Code:
<?php $a=10; $a=$a++ + ++$a; echo $a;
Ideone gives out 22, it was expected 23. Modification with prioritization $a=($a++) + (++$a);
does not save. Question: Is the pre / post-increment behavior described in the PHP interpreter, or is this the classic undefined behavior?
Update: Yes, I confused the code for 23, there was exactly $a = ++$a + ++$a
, here 22 without any questions, since the pre-increment is one. But the option $a= ++$a * (++$a + 2);
turned out to be much more interesting - the answer to the Ideone 154! The second option, if it is first calculated (++$a +2)
, 12 * 13 = 156. The question is valid - is the behavior of the PHP interpreter when calculating expressions with a pre / post-increment set, or different depending on the implementation?
$a = (++$a) * (++$a + 2)
. I can not confirm the document so far. - Alex Belyaev++$a
would be calculated first, and the answer would be 156. - Vesper