< ?php
/**
* Outputs/Debugs a variable and shows where it was called from
* @param mixed $var
* @param boolean $dump
* @param boolean $backtrace
* @return string
*/
function debug($var, $dump = false, $backtrace = true) {
if (error_reporting() > 0) {
if ($backtrace) {
$calledFrom = debug_backtrace();
echo '' . trim(str_replace($_SERVER['DOCUMENT_ROOT'], '', $calledFrom[0]['file'])) . ' (line ' . $calledFrom[0]['line'] . ')';
}
echo '
';
$function = ($dump) ? 'var_dump' : 'print_r';
$function($var);
echo '
';
}
}
?>
Utilizzo
< ?php
debug($_SERVER);
// var_dump() instead of print_r()
debug($_SERVER, true);
// Do not display the backtrace
debug($_SERVER, false, false);
?>
fonte: www.sastgroup.com
...leggi tutto»