Better variable dumping for PHP
debug($variable)
prints html and source code friendly variable informationinspect($variable)
returns the variable information as a string
Associative arrays are printed as:
{
key: 'value'
'key 2': 'value 2'
}
Numeric arrays:
[
'value 1',
'value 2',
'value 3'
]
Objects:
Name\Space\Foo#0 (
attribute: 'value',
*privateAttribute: 'value'
)
The asterisk before privateAttribute
signifies that this attribute is private.
The #0
after the class signifies the instance of the class, if this instance occurs again, its contents won't be printed to prevent recursion e.g.
$x = new Foo;
$y = new Bar;
$x->self = $x;
$x->other = $y;
$y->self = $y;
$y->other = $x;
debug($x);
Outputs:
Foo#0 (
self: Foo#0,
other: Bar#0 (
self: Bar#0,
other: Foo#0
)
)
Set the max depth to dump only shallow data:
$x = new Foo;
$x->bar = array(1, 2, 3);
$array = array('foo' => $x);
debug($array, 2);
Outputs:
{
foo: Foo#0: (
bar: [
...
]
)
}