Drupal coder

A better print_r for debugging purposes

We all use print_r from now to then in our code to quickly debug a statement. But it's easy to forget this and leave this in your code for unexperienced programmers. Sometimes it's in a conditional section and than it's very hard to keep track of these.
This information ruins your page and makes your clients very unhappy.

A better alternative is to use the dpr function, which is provided by the devel module. This function checks if a user has access to development information via a permission 'access devel information'.

And if you even want to top that off, do a function_exists to make sure you have devel installed (or some other module to provide this function).

$a = array('test');
if(function_exists('dpr')) dpr($a);
October 09, 2008debugging, Devel, Drupal, module development

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options