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 dprint_r
(A debug version of the popular print_r
function in PHP). Well who has used these ones?
dpr
– Shortcut fordprint_r
.dvr
– Similar todpr
, but usesvar_dump
instead ofprint_r
.dpm
– Similar todpr
butprint_r
's a variable as a message usingdrupal_set_message
.dvm
– Similar todpm
but usesvar_dump
instead ofprint_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!