You are here

Devel's helper functions

Submitted by devblog on Mon, 23/11/2009 - 20:34

Blagged from http://ratatosk.backpackit.com/pub/1836982-debugging-drupal for reference

dpm()

Prints a variable to the ‘message’ area of the page using drupal_set_message(). You can use this function to keep track of one or more variables when you’re working on the code running your site. Because the Devel module now comes with Krumo, the output is compact and unobtrusive.

dpm($input, $name = NULL)

If, for some reason, you are not using Krumo, you can use the $name parameter to distinguish between different calls to dpm().

You can see example output in the screenshot “dpm()” below.
dvm()

Uses var_dump() to print a variable to the ‘message’ area of the page using drupal_set_message(). The output of this function is harder to read than the Krumo-based output of dpmt(), but it can be useful if you need to copy and paste it to another application.

dvm($input, $name = NULL)

If, for some reason, you are not using Krumo, you can use the $name parameter to distinguish between different calls to dvm().

You can see example output in the screenshot “dvm()” below.
dpr()

Pretty-prints a variable to the browser (without using krumo). The output is displayed in the page header, making this a good choice if your theme doesn’t print the $messages variable.

dpr($input, $return = FALSE, $name = NULL)

Set the second parameter to TRUE if you want to return a string instead of printing it.

You can use the $name parameter to distinguish between different calls to dpr().

You can see example output in the screenshot “dpr()” below.
dvr()

Uses var_dump() to pretty-print a variable to the browser (without using krumo). The output is displayed in the page header, making this a good choice if your theme doesn’t print the $messages variable.

dvr($input, $return = FALSE, $name = NULL)

Set the second parameter to TRUE if you want to return a string instead of printing it.

You can use the $name parameter to distinguish between different calls to dvr().

You can see example output in the screenshot “dvr()” below.
kpr()

Pretty-prints a variable to the browser using krumo. The output is displayed in the page header, making this a good choice if your theme doesn’t print the $messages variable. Since it uses Krumo, it has the added advantage that the output is very compact and unobtrusive.

kpr($input, $return = FALSE, $name = NULL)

Set the second parameter to TRUE if you want to return a string instead of printing it.

You can see example output in the screenshot “kpr()” below.
dargs()

Prints the arguments passed into the current function. In this case, the arguments are ‘foo’, and ‘42’. You can use this function if you’re not completely sure of the arguments received by a specific Drupal hook or function in the code you’re working on.

dargs()

You can see example output in the screenshot “dargs()” below.
dd()

Logs any variable to a file named “drupal_debug.txt” in the site’s temp directory. All output from this function is appended to the log file, making it easy to see how the contents of a variable change as you modify your code.

If you’re using Mac OS X you can use the Logging Console to monitor the contents of the log file.

If you’re using a flavor of Linux you can use the command “tail -f drupal_debug.txt” to watch the data being logged to the file.

dd($data, $label = NULL)

You can see example output in the screenshot “dd()” below.
ddebug_backtrace()

Prints the function call stack.

ddebug_backtrace()

You can see example output in the screenshot “ddebug_backtrace()” below.
db_queryd()

This function is the debugging version of db_query(), which prints the query and any error messages to the browser. This function is useful if you want to monitor a few database queries but don’t need Devel module’s list of all database queries used to build the current page.

db_queryd($query, $args = array())

You can see example output in the screenshot “db_queryd()” below.

Vertical Tabs

Add new comment