Tagged debug

WP-dBug

A colleague at work found dBug, a sweet PHP class for creating nice, clean debug output and implemented it into our framework. While debugging a different WordPress plugin, I realized how nice it would be to have similar output in WordPress. Thanks to some planned system downtime during a major datacenter move where I work, I finally had a chance to create a plugin to implement the dBug class. It’s basically a wrapper for the original class–all the credit should and does go to Kwaku Otchere for creating what is (in my opinion) the nicest-looking debug output I’ve ever seen. It’s simple as heck to use the plugin: just install it, activate, and call it like this:

[cc lang=”php”]
function fill_my_screen_with_stuffs (){
global $wpdb;
wp_dbug( $wpdb );
wp_die( ‘Did you know WP 3.0 has a cool new wp_die() function?’ );
}

[/cc]

As a side note, you can use dBug for whatever code you want–just include the single PHP file and use it according to the author’s instructions.

Use the awesome dBug class in CakePHP

If you program in PHP, you’re probably annoyed by var_dump, because the output is really difficult to read, especially if the var is a nice big object or array. If you’re used to working in CakePHP, you probably use pr() because it’s slightly better than var_dump.

At work, however, we use a class called dBug, which gives you color-coded variable output with collapsible hierarchy, etc. In other words, a pretty awesome debugging tool. To get this functionality in your Cake app, just do the following:

  1. Download dBug.php from the author’s site and put it in your app/ directory.
  2. In your app_controller.php (or whatever your base class is), add the following line:
    [cc lang=”php”]include_once(“dBug.php”); [/cc]
  3. You can get beautiful dBug output by calling the following in a model, controller, or even view:
    [cc lang=”php”]new dbug($myvariable);[/cc]

That’s it! You’ll probably never use pr() again 🙂