Sunday, February 14, 2010

When var_dump is not enough.

Introduction


Using this library you can browse the content of complex variables, one nested level at the time by using commands such as zoomin, zoomout and exit. Currently, this class should only be used for command line applications. Web browsable functionality will be added later using through firephp/firebug.

Example


By executing the snippet below you will see the following screen. At this point you can decide to exit (or zoomout), or zoom in to nested variable links [1] and [2].


<?php

require_once("rawdev/RawDev.php");
require_once(RAWDEV_LIB.'/Util/Dumper.php');

class Test {

var $a='hi';
var $b = array(1, 2);

}

$complex = array(1, 'hi', array(99, 17), 'std' => new stdClass(), new Test(), array());

RDumper::dump($complex);

?>

Conclusion

For command line application development this beats var_dump and will save you a ton of time when debugging.

Links

RDumper API Doc

Future enhancements

Color coding?

4 comments:

  1. If var_dump isn't enough, maybe you need an IDE with a debugger...

    ReplyDelete
  2. @Richard: Really funny.

    Unfortunately there are lots of people still stuck with the var_dump style of debugging. However, they try to evolve and beautify var_dumps.

    ReplyDelete
  3. when debug in browser, I thing firephp is a better choice.

    ReplyDelete
  4. @@ thanks guys, IDE+command line dumper + firephp = complete set of tools

    -- I am also looking to expand RawDev with other XDebug functionality such as profiling.

    Debug PHP code in an IDE in less than one hour. Using an IDE debugger in addition to RawDev's debugging tools will give you a comprehensive set of debugging tools.

    http://blog.bokenkamp.com/2010/02/basic-open-source-ide-setup-for-php.html

    This quick tutorial is targeted to Mac OS X and Linux but should be clear enough for other platforms.

    ReplyDelete