[Drupal] Debugging Drupal with dpr() function

| | 1 min read

As a drupal developer, there were times when I was stuck at some point. At these times, 'devel' module came to my rescue. There are many debugging functions provided by devel. Those are dpm, dpr, dvm, dvr etc. Here, I am going to explain 'dpr()' provided by devel module.

'dpr' is actually an alias for 'dprint_r' function. dpr function prints a variable in the browser without using krumo other than 'dpm()s' which uses krumo display. The output of dpr function is printed inside the page header. So even if you haven't given $messages to print in your template file, you could see the result.
The dpr function is defined as follows:

function dpr($input, $return = FALSE, $name = NULL) {
  return dprint_r($input, $return, $name);
}

The syntax to use dpr is same as that of dpm. Suppose you want to print the variable $form. To use dpr, just add

 dpr($form); 

If you don't want to print the variable but to return it as a string, then you may use:

dpr($form, $return = TRUE, $name = NULL); 
// The parameter '$name' distinguishes different call to dpr(). 

Trust me when I say that dpr has its own advantage while comparing with print_r(). Refer the screenshots if you don't believe me.

dpm


dpr


print_r

Hope this helps!!!

Reference:
http://ratatosk.net/drupal/tutorials/debugging-drupal.html