Why the original refpount of the array is 2 in php7.1

$a = [1, 2, 3]; xdebug_debug_zval('a'); $b = $a; xdebug_debug_zval('a'); unset($b); xdebug_debug_zval('a'); 

This will lead to the conclusion

 a: (refcount=2, is_ref=0)=array (2 => (refcount=0, is_ref=0)=1, 1 =>(refcount=0, is_ref=0)=2) a: (refcount=3, is_ref=0)=array (2 => (refcount=0, is_ref=0)=1, 1 => (refcount=0, is_ref=0)=2) a: (refcount=2, is_ref=0)=array (2 => (refcount=0, is_ref=0)=1, 1 => (refcount=0, is_ref=0)=2) 

why in the first line refcount is 2

+5
source share
1 answer

This seems to be related to the "Internal Representation of Values ​​in PHP 7".

Follow this comment in the Reference Counting Basics in the PHP manual.

And details on nikic Blog : "Zvals in PHP 7".

See also xdebug commit on github . This may also be part of the answer.

Hope this helps.

0
source

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


All Articles