<?php
if (!function_exists('debug_print_backtrace')) {
function debug_print_backtrace()
{
// Get backtrace
$backtrace = debug_backtrace();
// Unset call to debug_print_backtrace
array_shift($backtrace);
// Iterate backtrace
$calls = array();
foreach ($backtrace as $i => $call) {
if (!isset($call['file'])) {
$call['file'] = "Unknown";
}
if (!isset($call['line'])) {
$call['line'] = "Unknown";
}
$location = $call['file'] . ':' . $call['line'];
$function = (isset($call['class'])) ?
$call['class'] . '.' . $call['function'] :
$call['function'];
$params = '';
if (isset($call['args'])) {
$args = Array();
foreach ($call['args'] as $arg) {
if (is_scalar($arg)) {
$args[] = gettype($arg)." ".$arg;
} else if (is_object($arg)) {
$args[] = get_class($arg);
} else {
$args[] = gettype($arg);
}
}
$params = implode(', ', $args);
}
$calls[] = sprintf('#%d %s(%s) called at [%s]',
$i,
$function,
$params,
$location);
}
echo implode("\n", $calls);
}
}
?>