NumberTwo
NumberTwo is a classy variable dumper., (*1)
, (*2)
When var_dump or print_r is too verbose or unpleasant to read, go for NumberTwo., (*3)
Scalars
echo NumberTwo::dump(null);
// null
echo NumberTwo::dump(true);
// true
echo NumberTwo::dump(false);
// false
echo NumberTwo::dump(1);
// 1
echo NumberTwo::dump('foo');
// "foo"
Arrays
echo NumberTwo::dump(array('foo', 'bar'));
[
0 => "foo"
1 => "bar"
]
echo NumberTwo::dump(array('foo' => 'bar'));
[
"foo" => "bar"
]
Objects
echo NumberTwo::dump($object);
My\ClassWithPublicProperties {
foo: "aaa"
bar: "bbb"
}
You can configure the recursive depth:, (*4)
echo NumberTwo::dump($otherObject, 2);
UnitTest\NumberTwo\PublicProperties {
foo: UnitTest\NumberTwo\PublicProperties {
foo: UnitTest\NumberTwo\PrivateProperties { ... }
bar: null
}
bar: null
}
Filters
You may want to pre-process some objects that are to be dumped., (*5)
For that, you can use the filters:, (*6)
$filters = array(new MyFilter());
echo NumberTwo::dump($otherObject, 2, $filters);
Doctrine Collection
NumberTwo provides a filter for Doctrine's collections:, (*7)
use NumberTwo\Filter\DoctrineCollectionFilter;
$filters = array(new DoctrineCollectionFilter());
echo NumberTwo::dump($otherObject, 2, $filters);
This filter will turn any Collection (ArrayCollection, PersistentCollection, …) into a PHP array (using the toArray() method)., (*8)
Doctrine proxies
NumberTwo provides a filter for Doctrine's proxies:, (*9)
use NumberTwo\Filter\DoctrineProxyFilter;
$filters = array(new DoctrineProxyFilter());
echo NumberTwo::dump($otherObject, 2, $filters);
This filter will load uninitialized proxies and clean up properties., (*10)
Feel free to submit other filters in a pull request., (*11)
License
NumberTwo is under the MIT license., (*12)