var_dump implementation that limits the depth of nested objects

Mert Nuhoglu picture Mert Nuhoglu · Nov 15, 2012 · Viewed 7.2k times · Source

In the previous question, I asked for an alternative implementation of var_dump that allowed limiting the output of the depth of nested arrays.

Abhishek answered the question. But that function works only on nested arrays. It does't work on object graphs.

How can a var_dump implementation work on object graphs and limit the output of the depth of nested objects?

Answer

deceze picture deceze · Nov 15, 2012

By far the easiest solution is to install the xdebug extension (which is a good idea anyway). It overrides var_dump with a version which limits output to a configurable depth.