PHP: Copy On Write and Assign By Reference perform different on PHP5 and PHP7
问题 We have a piece of simple code: 1 <?php 2 $i = 2; 3 $j = &$i; 4 echo (++$i) + (++$i); On PHP5, it outputs 8, because: $i is a reference, when we increase $i by ++i , it will change the zval rather than make a copy, so line 4 will be 4 + 4 = 8 . This is Assign By Reference . If we comment line 3, it will output 7, every time we change the value by increasing it, PHP will make a copy, line 4 will be 3 + 4 = 7 . This is Copy On Write . But in PHP7, it always outputs 7. I've checked the changes