PHP: Collapsing Object In Var_dump
Jun 25th, 2013When using var_dump()
in an object-oriented world, often the output is too big because of objects and therefore not readable. Here a function to collapse objects, and make debugging easier.
To collapse an object, we replace it by a string with its classname:
"Object(Symfony\Component\HttpFoundation\Request)"
We recursively traverse the data structure, replacing each object by a string.
Then, calling var_dump
on the data structure with collapsed objects will produce a more readable output: