NikiC在
another thread中说:
Right before [a foreach] iteration the $array is “soft copied” for
use in foreach. This means that no actual copy is done, but only the
refcount of the zval of $array is increased to 2.
但是,我的测试代码显示了不同的结果:
$array = array(0, 1, 2);
xdebug_debug_zval('array'); // refcount=1, is_ref=0
// so far so good
foreach ($array as $key => $value) {
xdebug_debug_zval('array'); // refcount=3, is_ref=0
} // why is refcount 3 instead of 2?
只需查看代码,我们最多可以看到两个数组变量.
为什么引用3?
foreach运行后为什么不引用refcount?