debug_zval_dump

(PHP 4 >= 4.2.0, PHP 5, PHP 7)
Dumps a string representation of an internal zend value to output
void debug_zval_dump ( mixed $variable [, mixed $... ] )

Dumps a string representation of an internal zend value to output.

Parameters:
variable

The variable being evaluated.

Returns:

No value is returned.

Examples:
debug_zval_dump() example
<?php
$var1 = 'Hello World';
$var2 = '';

$var2 =& $var1;

debug_zval_dump(&$var1);
?>

The above example will output:

&string(11) "Hello World" refcount(3)
The above example will output:

The refcount value returned by this function is non-obvious in certain circumstances. For example, a developer might expect the above example to indicate a refcount of 2. The third reference is created when actually calling debug_zval_dump().

This behavior is further compounded when a variable is not passed to debug_zval_dump() by reference. To illustrate, consider a slightly modified version of the above example:

<?php
$var1 = 'Hello World';
$var2 = '';

$var2 =& $var1;

debug_zval_dump($var1); // not passed by reference, this time
?>

string(11) "Hello World" refcount(1)
The above example will output:

Why refcount(1)? Because a copy of $var1 is being made, when the function is called.

This function becomes even more confusing when a variable with a refcount of 1 is passed (by copy/value):

<?php
$var1 = 'Hello World';

debug_zval_dump($var1);
?>

string(11) "Hello World" refcount(2)
See also:

var_dump() -

debug_backtrace() -

References Explained -

» References Explained (by Derick Rethans) -

doc_php
2016-02-24 16:13:55
Comments
Leave a Comment

Please login to continue.