1

This is my setting:
display_startup_errors = on
display_errors = On
error_reporting = E_ALL | E_STRICT

//code1:
$a = "abcd";
xdebug_debug_zval('a');

The above line of code would create a zval container and associate it with the symbol a'. And would give the following o/p.

a: (refcount=1, is_ref=0)='abcd' 

consider the folowing code now:

//code2:
$a;
echo":";xdebug_debug_zval('a'); echo "<br/>";
$a = "abcd";
xdebug_debug_zval('a'); echo "<br/>";

would generate the o/p;

:
a: (refcount=1, is_ref=0)='abcd' 

from PHP manual's Reference Counting Basics : A zval container is created when a new variable is created with a constant value

Does this mean that,

1] No symbol is created when code similar to line 1 of code2 i.e. $a; is encountered. Since     xdebug_debug_zval does not find the symbol / variable name 'a'. As per the statement from     Reference Counting Basics no zval container is created.
2] A symbol is created only when code similar to line 3 of code2 i.e. $a = "abcd"; is encountered.     i.e. a symbol gets created only when the variable is associated with a constant value & as per the     statement from Reference Counting Basics a zval container is created and is associated with the     symbol 'a'. And that line 1 of code2 i.e. $a; is a useless piece of code.

For info on xdebug_debug_zval visit here.

hakre
  • 193,403
  • 52
  • 435
  • 836
ThinkingMonkey
  • 12,539
  • 13
  • 57
  • 81

1 Answers1

0


$b;
xdebug_debug_zval('b'); echo "<br/> ";
echo $b;

The above code would output:

Notice: Undefined variable: b in /path/to/file/file.php on line 'some line number'

The xdebug_debug_zval is not throwing any error in the above code though!!

Assigining $b a constant value,

$b = "hello";
xdebug_debug_zval('b'); echo "<br/> ";
echo $b;

b: (refcount=1, is_ref=0)='hello' hello

The above code proves that a 'symbol'/'variable name' gets created only when a constant is associated with it
i.e.
A 'symbol'/'variable name' gets created only when there is a possibility of a zval getting created.

A symbol can be created if a variable is assigned NULL.

$b = null;
xdebug_debug_zval('b'); echo "<br/> ";
echo $b;

The above code will output:

b: (refcount=1, is_ref=0)=NULL

ThinkingMonkey
  • 12,539
  • 13
  • 57
  • 81