I was browsing around the Devel Module the other day and I noticed a few functions that are not mentioned in any documentation that I've seen but make life even easier, as if Devel doesn't make it easy enough! Almost everyone that's used Devel will be familiar with <strong>dprint</strong>_r (A debug version of the popular print_r function in PHP). Well who has used these ones?
dpr – Shortcut for dprint_r.dvr – Similar to dpr, but uses var_dump instead of print_r.dpm – Similar to dpr but print_r's a variable as a message using drupal_set_message.dvm – Similar to dpm but uses var_dump instead of print_r.The dpr simply "saves carpal tunnel syndrome" (as the comment for the function in devel.module says) and the dvr function is funky useful as it not only dumps the data but also the data TYPE too (eg, is this variable a integer zero or boolean false?). The dpm and dvm functions are useful as the message only gets printed out on a visible page. This makes form output debuging easier.
Who here has debug outputted the $form_values on a form_submit and spent a few minutes wondering why nothing came up (due to the redirect after submit) and then ended up adding exit calls to the code to see the output or enabling the form redirection interruption from the Devel Module? Well if you use dpm or dvm then you will get the form output in a message on the next visible page without any workflow interruption! Cool, eh!
These are REALLY useful commands! Thanks to Moshe for adding the var_dump variants and I can only assume it was Moshe's idea to have the shortcut dpr and dpm functions to start with!
4 Comments
I had no idea these existed.
I had no idea these existed. Saves me again some typing! :) Thanks!
Excellent stuff
Brilliant stuff, some excellent Drupal tips that I reckon will save me a bunch of time! Keep up the good Drupal work :)
Thanks
I new these existed, but had forgot the actual function names. Thanks :)
Arguments
If you scan devel.module you'll also see that these functions take arguments. Something I do when developing is stick dpr() in different hooks so I can track changes to an an object as it undergoes processing. This is a common one:
dpr($node, FALSE, __FUNCTION__.'->node');
This will dump $node to the screen along with the function name that fired it. If the second argument is TRUE it returns its value to the caller, which could be a logger function.