2

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).

Community
  • 1
  • 1
Nico
  • 439
  • 3
  • 16

1 Answers1

0

Unfortunately, since PHP 7 changed the way how variables are handled internally, it's not really possible for xdebug_debug_zval() to give fully accurate results any more.

Derick
  • 35,169
  • 5
  • 76
  • 99
  • Thanks for your response. Can you give me some sources in order I understand the way it changed? – Nico Jan 08 '18 at 07:29