I'm using xdebug_debug_zval
in order to understand how references changed between PHP 5 and PHP 7.
<?php
$array = array('k1', 'k2', 'k3');
echo PHP_VERSION. '<br/>';
foreach ($array as &$ref) {
}
unset($ref);
xdebug_debug_zval('ref');
xdebug_debug_zval('array');
PHP 5.5.9-1ubuntu4.14 :
5.5.9-1ubuntu4.14
array:
(refcount=1, is_ref=0),
array (size=3)
0 => (refcount=1, is_ref=0),string 'k1' (length=2)
1 => (refcount=1, is_ref=0),string 'k2' (length=2)
2 => (refcount=1, is_ref=0),string 'k3' (length=2)
PHP 7.0.8-0ubuntu0.16.04.3 :
7.0.8-0ubuntu0.16.04.3
ref:
(refcount=0, is_ref=0)*uninitialized*
array:
(refcount=1, is_ref=1)
array (size=3)
0 => (refcount=1, is_ref=1)string 'k1' (length=2)
1 => (refcount=1, is_ref=1)string 'k2' (length=2)
2 => (refcount=1, is_ref=1)string 'k3' (length=2)
Why in PHP 7 is_ref
is equal to 1 knowing that I have unset the reference and according to PHP documentation ? :
Note that if "refcount" is 1, "is_ref" is always FALSE.
PS : OPcache is disabled (opcache.enable=0
).