2

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?

Community
  • 1
  • 1
Mert Nuhoglu
  • 9,695
  • 16
  • 79
  • 117

3 Answers3

3

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.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • I just noticed you already mentioned xdebug in your other question. I'd suggest you try to fix whatever isn't working for you about it, instead of trying to find some entirely alternative solution. – deceze Nov 15 '12 at 12:49
  • I am already trying to fix it but I thought maybe an alternative implementation might solve the problem faster. Let's see... – Mert Nuhoglu Nov 15 '12 at 12:57
1

Check out some of the comments under the var_dump function info at php.net - http://php.net/manual/en/function.var-dump.php - They provide depth level controls for var_dump as well as few other goodies.

Kami
  • 19,134
  • 4
  • 51
  • 63
0

try dump_r.php (php 5.3+).

you can specify the depth to which you want the dump unfolded to and can interactively unfold more later. It will not actually limit the depth of the actual dump though, so if it's needed for performance reasons, it likely won't help in that department. Also, it's in HTML, I will probably add a text-only dump option in the future.

demo: http://o-0.me/dump_r/
repo: https://github.com/leeoniya/dump_r.php

also installable via Composer
require: "leeoniya/dump-r": "dev-master"
https://packagist.org/packages/leeoniya/dump-r

leeoniya
  • 1,071
  • 1
  • 9
  • 25