March 12, 2009

Krumo, a PHP debugging tool that I’m using in Drupal

Filed under: Tips — Tags: , — Webopius @ 8:15 pm

OK, you’re probably going to tell me that everyone knows about Krumo but I’ve been developing in PHP for about 5 years and I’d never heard of it. Yes, alright, I’m a foolish developer.

Anyway, there I was writing a new Drupal 6 module when I started browsing the source code of the Devel module that I use quite a bit to diagnose issues. In the devel.module file, there was a line has_krumo() along with a comment about ‘anyone may call krumo() as needed’.

Well, that got my curiosity going so I went to have a look and I think Krumo is a fantastic tool. In plain English (if you’re a PHP developer!), Krumo is a replacement for the print_r() function used by PHP developers everywhere.

Krumo home page

Print_r() is intended to present a variable passed as a parameter in a human readable format. Hmm, here’s what print_r() thinks human readable looks like (click on the image to view full size):

Not good is it? This was a dump of the $node variable in Drupal 6 called using print_r($node). Now, here’s how the same data looks using krumo($node):

Much easier to read and literally a one line change.

Anyway, Krumo is my current recommended tool. Click on the link to the right to go to the Krumo home page. Krumo is built into the Drupal 6 devel module.

  • Tags