the result of the following statement should give 9 : (using java or js or c++)
i = 1;
i += ++i + i++ + ++i;
//i = 9 now
but in php
the same statements will give 12 ?!
$i = 1;
$i += ++$i + $i++ + ++$i;
echo $i;
is this a bug or can anyone explain why ?
The answer is “because it’s PHP”. And PHP doesn’t make guarantees about that type of statement (incidentally, neither does C).
Yes, it could be considered wrong, but it’s PHP. See this “not a bug” bug report.