Drupal Devel - dpm() bork... and the No Devel module.

I got a message from a client that some admin portions of their site were failing to come up. This is a Drupal 7 multi-site install, with a pseudo-sandbox for playing/testing (different database but same codebase). This client was in China, so his daytime is literally my night! He spent several hours trying to figure out the problem… and it was such a little thing.

Devel was turned off, but an errant dpm() function was active.

Turns out that one of the modules active on both the sandbox and the live had a dpm() function for debugging, and the live site didn’t have the Devel module running. For those who don’t know, devel is a super handy module that helps with development (go figure), and in this case the dpm() function was outputting an object in the code so we could easily see what was in it and how our function needed to interact with it.

However, when the devel module is NOT on, there is NO dpm() function, and so you can seemingly bork your site (depending on where/how the function is being called). In this case, it was just on a handful of admin pages, so the damage was minimal. However, in the wrong place… this could possible take down a site.

Normally, we don’t have these floating about and they should be removed as soon as they are not needed… but, stuff happens and sometimes one or two may end up slipping through the cracks (like now). Worse, the code could exist on a live site (or be shared like here) OR be migrated over to the live site unknowingly. Not so good.

“No Devel” module - aka dpm() insurance

Today, I stumbled upon a newish module aptly called “No Devel” (sandbox - but it might get proper acceptance). Its very simple, but thats the genius of it. All it does is look to see if ANY of the devel functions are being called without devel being on, and if so, it creates a simple function to report the warning. Basically, it changes the PHP error into a PHP warning… which doesn’t kill the site, but does let you know there is an issue.

Now, you may or may not want this module… but something like it may be a good addition to your default “glue” module. You could also get in the habit of putting a simple IF statement in place when using dpm(), just to be on the safe side… maybe even create a snippet in your fav IDE to drop it in place every time. Something like this should work fine:

<?php
 
if (function_exists('dpm')) {
     
dpm($object_or_array_here);
  }
?>

If you want to get fancy, you can even set your arguments to have it only show on certain pages or under certain circumstances:

<?php
 
if (function_exists('dpm') & arg(0) == 'admin' & arg(2) == 'orders') {
     
dpm($order_statuses);
  }
?>

Or, you could get super fa-shmancy and create your own custom function (in your glue module) that just wraps around the dpm and use that:

<?php
function mydpm($input) {
  if (
function_exists('dpm')) {
     
dpm($input);
  } else {
      echo
'<pre>' . print_r($input, true) . '</pre>';
  }
}
?>

Regardless of how you choose to go… just remember that devel is powerful stuff, but you can’t get too sloppy with it. Or, conversely, if you are going to get sloppy (or are afraid you will, or another dev will, etc.), then just take precautions. Safe coding is happy coding!