Sep 132011
 

While I am a firm believer in TDD [Test Driven Development], we all know that a lot of the time you dump an object or variable to chase a bug down the rabbit hole. And while both print_r and var_dump are usable for this, especially after Xdebug made var_dump a lot nicer. However, this was not enough for me, I wanted more power, at first for dealing with the depth and recursion, so I built my own debug tool. It has grown quite a bit and it is available on Github [1].
It supports these features:

  • Automatic block recursive references (only show an object once)
  • Easy on-the-fly change of depth* Blacklist classes, keys and properties
  • Meta info about objects like access level of properties
  • Includes knowledge of where it dies when you debug-die
  • Alternative adapters for outputting to file, json or firephp
  • Inspect global defines
  • Output a trace of “how you got here”
  • Dump an api (method list) of an object

The tool is basically just a Debug class with an adapter (typically Html for browser output). It also comes with a css for styling the output as well as a “bootstrap” file where you can set up default values, import them from your framework and define convenience method. The most used such functions are d() and dd(). The first will debug dump any amount of variables with the default values. The second will dump and die, with an ob_flush, allowing you to use the debug dumping anywhere in your project without worrying about started output or headers etc.
You can try it for yourself, but here is a little screencast that demonstrates the kinds of outputs it shows:

http://www.youtube.com/watch?v=CBWFM_bs6nw

[1] https://github.com/alkemann/AL13/tree/master/al13_debug

 Posted by at 8:39 am