In PHP, var_dump() prints detailed information about one or more values, including their types and sizes. It is the most popular function for debugging.
Unlike echo or print_r(), var_dump() shows the exact type, such as int(5), string(3) "abc" or bool(true). For arrays and objects it prints every element, indented. It prints directly to the output and returns nothing.
Syntax
Call var_dump() with the values you need. Start with this line.
PHP
var_dump($value);
Call
What it does
var_dump(42)
Prints int(42).
var_dump('hello')
Prints string(5) "hello", showing the type and length.
var_dump($a, $b)
Prints both values, one after the other.
var_dump() writes straight to the output. To capture its text, wrap it in ob_start() and ob_get_clean(). In a browser, wrap the output in <pre> tags to keep the formatting.
Library declarations
PHP
var_dump(mixed ...$value): void
Parameters
Parameter
Description
value
Required. One or more values to dump. You can pass several values in one call and each is printed in order.
Return Value
Return Value
Description
void
var_dump() does not return anything. It prints its output directly.
PHP Examples
Example 1 — Dumping Simple Values
Dump an integer, a string, a float, a boolean and null, and look at how each type is shown.
The class has a public and a protected property. Both are shown by var_dump().
The first line shows the class name and the object id. #1 is the first object created in the script.
(2) is the number of properties. The properties are listed below with their names in quotes.
The protected label appears after the name. Public properties have no label.
Frequently Asked Questions
It prints the type and value of one or more variables. For arrays and objects it prints every element with its type, which makes it ideal for debugging.
var_dump() shows exact types and sizes, such as string(3) "abc". print_r() is shorter and easier to read but hides the type, so true shows as 1 and false shows as nothing.
var_dump() has no return option. Use ob_start() before it and ob_get_clean() after it to capture the output in a variable. You can also use var_export($value, true) for a different format.
Yes. var_dump($a, $b, $c) dumps all three values in order. Each one is printed in its own block.
PHP prints floats in their shortest exact form, so a float with no decimals shows as float(3). The type is still float, which is what var_dump() is telling you.