In PHP, debug_zval_dump() prints detailed internal information about one or more values, including their type, content and, for some types, a reference count.
It works like var_dump(), but adds a refcount() number that shows how many places share the same value in memory. This is a debugging tool for learning how PHP stores values. You will rarely need it in everyday code.
Syntax
Call debug_zval_dump() with the values you need. Start with this line.
PHP
debug_zval_dump($value);
Call
What it does
debug_zval_dump(42)
Prints int(42). Simple values print the same way as var_dump().
debug_zval_dump($a, $b)
Prints the details of each value in order, one after another.
debug_zval_dump($text)
Prints the string, its length and a refcount number.
Beginners can treat refcount as "how many variables point at this value". The exact number can differ between PHP versions and for fixed text written in your code (shown as interned), so never write logic that depends on it.
Library declarations
PHP
debug_zval_dump(mixed ...$value): void
Parameters
Parameter
Description
value
Required. The value to dump. You can pass more values separated by commas, and each one is printed in turn.
Return Value
Return Value
Description
void
Nothing is returned. The function sends its output straight to the browser or terminal.
PHP Examples
Example 1 — Dumping Simple Values
Scalar values and null have no reference count, so the output looks just like var_dump().
The text is built with . =, so PHP creates a normal string in memory.
$var2 = $var1 does not copy the text. Both variables point at the same string.
Two variables hold the string, and passing it to the function adds one temporary reference, so the count is 3.
The number is only a learning aid. It can change between PHP versions, so do not depend on it.
Frequently Asked Questions
It prints the type and value of the variables you give it, plus an internal reference count for some types. It is meant for debugging how PHP manages memory.
var_dump() shows the type and value. debug_zval_dump() shows the same thing and also adds refcount information, so you can see how many places share one value.
A refcount is a counter PHP keeps for a value in memory. When you copy a variable, PHP often shares the value and raises the counter instead of copying data. When the counter reaches zero, PHP frees the memory.
Passing a variable to a function creates a temporary extra reference for the duration of the call. This is why the number is usually one more than the count of variables that hold the value.
No. It is a low-level debugging aid and its output can change between PHP versions. For everyday debugging, use var_dump(), print_r() or a logger.