PHP var_dump() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Variables

Definition

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

ParameterDescription
valueRequired. One or more values to dump. You can pass several values in one call and each is printed in order.

Return Value

Return ValueDescription
voidvar_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.

PHP
<?php
var_dump(42);
var_dump('hello');
var_dump(1.5);
var_dump(true);
var_dump(null);

How It Works

  1. int(42) shows the type and the value. The word int tells you it is an integer.
  2. string(5) "hello" also shows the length. The number 5 is the count of characters.
  3. float(1. 5), bool(true) and NULL follow the same style. You always see the type first.
  4. var_dump() adds the new line itself. There is no need for PHP_EOL after it.

Example 2 — Arrays and Several Values

Dump an array that holds different types, then pass two values to a single var_dump() call.

PHP
<?php
var_dump([1, 'two', 3.0]);
var_dump('a', 2);

How It Works

  1. array(3) tells you the array has three elements. Each element is listed below it.
  2. Every item shows its key and its type. You can see that the list holds an int, a string and a float.
  3. 3. 0 is shown as float(3). The decimal part is dropped when it is zero, but the type stays float.
  4. Passing two values prints both. Each one is dumped in order, one after the other.

Example 3 — Dumping an Object

Dump an object and see how public and protected properties are labeled.

PHP
<?php
class Point {
    public $x = 1;
    protected $y = 2;
}

var_dump(new Point());

How It Works

  1. The class has a public and a protected property. Both are shown by var_dump().
  2. The first line shows the class name and the object id. #1 is the first object created in the script.
  3. (2) is the number of properties. The properties are listed below with their names in quotes.
  4. 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.

Next: var_export()

var_export() outputs or returns a string of valid PHP code that represents a value. If you.

var_export() 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