our insights on web development and the Drupal CMS

Prettier PHP variable debugging

Before I had the pleasure of coming to work for Rock River Star I was developing e-commerce platforms in ColdFusion. Thankfully I'm no where near ColdFusion anymore, but the one thing I miss is how useful the <cfdump> tag was and how nice the output was. Developing in PHP has always left something to be desired in variable output, whether it was the print_r or var_dump functions. One day, after Googling for something better I stumbled across dBug which takes ColdFusions dump styles and applies them to your PHP variables.

Usage of dBug is extremely simple, you can pass it strings, arrays, objects, classes, database results and XML. For example:

$variable = array(
       "inner third 1",
         "inner third 2"=>"yeah"),
new dBug($variable);

outputs this:


Drupal has some pretty nice variable debugging features with the Devel module but I find that it lacks in some areas, specifically database results. I've searched through the Devel and Krumo examples for something that will make database result output somewhat readable but found only the DB_QUERYD(), which "is the debugging version of db_query(), which prints the query and any error messages to the browser". So basically it only shows you the query that was used and any errors that may have arisen from that query. dBug on the other hand can take a simple query result handle and turn it into this:

One other thing I found is the Drupal for Firebug module and Firefox extension, which when working together puts nearly all of the information you need right into Firebug for you. Any method of debugging you choose is fine, I'm just seeking to show people how useful dBug is for me, especially since it isn't Drupal dependent. If you'd like to see more examples you can see them on the dBug site.