Writing

Debug Function

Here is a debugging function that I use when I am not working in Drupal. I am spoiled by the Devel module and dpm() so I wrote this to make it easy to inspect my variables.

<?php
function debug($variable = NULL, $label = NULL, $return = FALSE, $debug = TRUE, $status = 'success') {
$output = FALSE;
if (
$print !== NULL) {
$output = '<pre>';
$output .= print_r($variable, TRUE);
$output .= '</pre>';
}
if (
$label) {
$output = '<strong>' . $label . ': </strong>' . $output;
}
if (
$debug) {
$type = gettype($variable);
$bt = debug_backtrace();
$caller = array_shift($bt);
$output .= '<br />' . $type . ' variable called from ' . $caller . ' on line ' . $caller;
}
if (
$output) {
$output = '<div>' . $output . '</div>';
}
if (!
$return) {
if (
function_exists('set_message')) {
set_message($output, $status);
} else {
print
$output;
}
}
return
$output;
}
?>
Writing