为什么在php7.1中数组的初始引用数为2

时间:2018-01-22 14:04:32

标签: php arrays xdebug

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

这将输出

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)

为什么在第一行中引用计数为2

1 个答案:

答案 0 :(得分:0)

这似乎是由于“PHP 7中的内部值表示”。

在PHP手册的Reference Counting Basics中关注此评论。

nikic's Blog中的详细信息:“PHP 7中的Zvals”。

请参阅此xdebug commit on github。它也可能是答案的一部分。

希望它有所帮助。