PHP Post and preincrement

I found some strange calculation in PHP, for example:

$c=5;

$r = $c + ($c++ + ++$c);

echo $r;

Why is the result 19, not 17?

thank

+4
source share
1 answer

The result must be unspecified. Please read the following PHP spec:
https://github.com/php/php-langspec/blob/master/spec/10-expressions.md

, , , . , , , . . , . (, $list1 [$ i] = $list2 [$ ++], , $ - $i, . , $j = $i + $i ++, , $ - $i, . , f() + g() * h(), , , ).

PHP: enter image description here

+3

Source: https://habr.com/ru/post/1688081/


All Articles