PHP debug_zval_dump() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Variables

Definition

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);
CallWhat 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

ParameterDescription
valueRequired. The value to dump. You can pass more values separated by commas, and each one is printed in turn.

Return Value

Return ValueDescription
voidNothing 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().

PHP
<?php
debug_zval_dump(42);
debug_zval_dump(3.5);
debug_zval_dump(true);
debug_zval_dump(null);

How It Works

  1. debug_zval_dump(42) prints the type and value: int(42).
  2. A float prints as float(3. 5).
  3. A boolean prints as bool(true) or bool(false).
  4. null prints as NULL. None of these simple types need a refcount number.

Example 2 — Dumping Several Values at Once

Because the function accepts more than one argument, you can inspect many values in a single call.

PHP
<?php
$count = 7;
$price = 1.5;
$active = false;

debug_zval_dump($count, $price, $active);

How It Works

  1. Three variables are created with different types.
  2. All three are passed to one debug_zval_dump() call, separated by commas.
  3. PHP prints each value on its own line, in the same order you passed them.
  4. This is handy when you want a quick look at several variables without repeating the call.

Example 3 — Watching the Reference Count

A longer string is shared between variables instead of being copied. The refcount shows how many places use it.

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

debug_zval_dump($var1);

How It Works

  1. The text is built with . =, so PHP creates a normal string in memory.
  2. $var2 = $var1 does not copy the text. Both variables point at the same string.
  3. Two variables hold the string, and passing it to the function adds one temporary reference, so the count is 3.
  4. 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.

Next: doubleval()

doubleval() is an alias of floatval(). It converts a value to a floating-point number and .

doubleval() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful