Let\'s face it, debug_backtrace()
output is not very pretty. Did anyone code a wrapper?
And what\'s your favourite pretty var_dump()
(which is
Gonna add mine to the rest of the answers here.
If you have bootstrap and jquery installed, it's even more useful and compact, but its not neccessary.
function prettyPrintBackTrace() {
$backtrace = "\nFull Backtrace\n";
foreach (debug_backtrace() as $key => $trace) {
if(($trace['function'] ==__FUNCTION__) || ($trace['function'] == "fail")) {continue;}
$class = (array_key_exists('class', $trace) ? "class ({$trace['class']})" : false);
$exp = explode("/",$trace['file']);
$exp[count($exp)-1] = "" . end($exp) . "";;
$filename = implode("/",array_splice($exp, -4));
$backtrace .= "/{$filename}:{$trace['line']}, ";
if((isset($trace['args'])) && (is_array($trace['args']))) {
if( (is_string($trace['args'][0])) && (substr($trace['args'][0],-4) == ".php") && (count($trace['args'] == 1)) ) {
// It was most likely a php include of some sort.
$exp = explode("/",$trace['args'][0]);
$filename = implode("/",array_splice($exp, -2));
$backtrace .= "function {$trace['function']}({$filename})\n";
} else {
// Finish the line and move on.
$backtrace .= "function {$trace['function']}() \n";
$backtrace .= "";
$args = array();
foreach($trace['args'] as $key => $val) {
if($val) $args[(!is_numeric($key) ? "key" : false)] = $val;
}
foreach($args as $count => $a) {
$backtrace .= ($count != (count($args) -1) ? "├" : "└");
$value = $a;
if($a === true) $value = "true";
if($a === false) $value = "f alse";
$backtrace .= "─ ".(!is_numeric($count) ? $count." " : false).var_export($value,1)."\n";
}
$backtrace .= "";
}
}
}
return $backtrace;
}
I hope that helps someone. I've tried to make it as compact as possible.