Skip to main content
The dump command displays a detailed, formatted representation of any object or primitive value. It’s like var_dump() but significantly more readable and powerful.

Syntax

dump [options] <target>

Arguments

target
code
required
An object, array, primitive, or expression to dump

Options

--depth
integer
default:"10"
Maximum depth to traverse when dumping nested structures. Deeper levels will show ellipsis (...).
--all
flag
Alias: -aInclude private and protected properties when dumping objects.

Usage Examples

Dump a Variable

>>> $name = 'Alice'
>>> dump $name
"Alice"

Dump an Array

>>> $data = ['name' => 'Bob', 'age' => 30, 'active' => true]
>>> dump $data
[
  "name" => "Bob",
  "age" => 30,
  "active" => true,
]

Dump an Object

>>> $date = new DateTime('2024-01-15')
>>> dump $date
DateTime {#123
  +date: "2024-01-15 00:00:00.000000",
  +timezone_type: 3,
  +timezone: "UTC",
}

Dump with Private Properties

>>> dump -a $object
>>> dump --all $object
class User {
    public $name = 'Alice';
    protected $email = '[email protected]';
    private $password = 'secret';
}

>>> $user = new User()
>>> dump $user
User {#456
  +name: "Alice",
}

>>> dump -a $user  
User {#456
  +name: "Alice",
  #email: "[email protected]",
  -password: "secret",
}
Notice the visibility prefixes:
  • + for public
  • # for protected
  • - for private

Dump Nested Structures

>>> $complex = [
...     'user' => ['name' => 'Alice', 'meta' => ['role' => 'admin']],
...     'settings' => ['theme' => 'dark']
... ]
>>> dump $complex
[
  "user" => [
    "name" => "Alice",
    "meta" => [
      "role" => "admin",
    ],
  ],
  "settings" => [
    "theme" => "dark",
  ],
]

Control Depth

>>> dump --depth=2 $deeplyNested
>>> dump --depth=1 $complex
>>> $deep = ['a' => ['b' => ['c' => ['d' => ['e' => 'value']]]]]

>>> dump --depth=2 $deep
[
  "a" => [
    "b" => [...],
  ],
]

>>> dump --depth=5 $deep
[
  "a" => [
    "b" => [
      "c" => [
        "d" => [
          "e" => "value",
        ],
      ],
    ],
  ],
]

Dump Expressions

You can dump the result of any expression:
>>> dump array_merge(['a' => 1], ['b' => 2])
[
  "a" => 1,
  "b" => 2,
]

>>> dump $object->getSettings()
>>> dump SomeClass::staticMethod()

Dump the Last Result

Use the special $_ variable:
>>> 2 + 2
= 4
>>> dump $_
4

>>> new DateTime()
= DateTime {...}
>>> dump $_
DateTime {#789 ...}

Output Formatting

The dump command provides rich formatting:

Primitives

>>> dump 42
42

>>> dump 3.14  
3.14

>>> dump true
true

>>> dump null
null

Strings

>>> dump "Hello\nWorld"
"Hello\nWorld"

>>> dump 'Long string...'
"Long string..."

Arrays

Arrays show keys and values with proper indentation:
>>> dump [1, 2, 3]
[
  0 => 1,
  1 => 2,
  2 => 3,
]

Objects

Objects show:
  • Class name
  • Object ID
  • Properties with visibility indicators
  • Proper nesting
ClassName {#123
  +publicProp: "value",
  #protectedProp: 42,
  -privateProp: [...],
}

Resources

>>> $fp = fopen('php://memory', 'r')
>>> dump $fp
resource(stream) {#45}

Circular References

Circular references are detected and marked:
>>> $a = ['name' => 'A']
>>> $b = ['name' => 'B', 'ref' => &$a]
>>> $a['ref'] = &$b
>>> dump $a
[
  "name" => "A",
  "ref" => [
    "name" => "B",  
    "ref" => [circular reference],
  ],
]

Comparison with var_dump

>>> dump $user
User {#123
  +name: "Alice",
  +email: "[email protected]",
  +roles: [
    0 => "admin",
    1 => "user",
  ],
}
The dump output is more readable with better formatting and color highlighting.

Magic Variables

After dumping an object, magic variables are set:
>>> dump $user
>>> echo $__class
User
>>> echo $__namespace
App\Models

Common Use Cases

Inspect API Responses

>>> $response = $client->get('/api/users')
>>> dump $response->getBody()

Debug Complex Data Structures

>>> dump $request->all()
>>> dump $_SESSION
>>> dump $_SERVER

Examine Object State

>>> $model = User::find(1)  
>>> dump -a $model
Shows all properties including private ORM internals.

Compare Values

>>> dump $expected
>>> dump $actual

Inspect Closures

>>> $closure = function($x) { return $x * 2; };
>>> dump $closure
Closure {#234
  +parameter: [
    "$x" => "<required>",
  ],
}

Tips

Use dump $_ to inspect the last expression result:
>>> $obj->complexMethod()->chain()->calls()
>>> dump $_  // See what was returned
Combine with --all to debug private state:
>>> dump -a $eloquentModel
Reveals internal attributes, relations, etc.
Adjust depth for large objects:
>>> dump --depth=3 $bigObject  // Less detail
>>> dump --depth=20 $bigObject // More detail
Very large objects may produce overwhelming output. Start with a shallow depth:
>>> dump --depth=1 $huge

See Also

  • ls - List object properties and methods
  • doc - Read object documentation
  • show - View object’s source code

Build docs developers (and LLMs) love