Here's a function that returns a string with the same information shown in debug_print_backtrace(), with the option to exclude a certain amount of traces (by altering the $traces_to_ignore argument).
I've done a couple of tests to ensure that it prints exactly the same information, but I might have missed something.
This solution is a nice workaround to get the debug_print_backtrace() information if you're already using ob_start() in your PHP code.
<?php
function get_debug_print_backtrace($traces_to_ignore = 1){
$traces = debug_backtrace();
$ret = array();
foreach($traces as $i => $call){
if ($i < $traces_to_ignore ) {
continue;
}
$object = '';
if (isset($call['class'])) {
$object = $call['class'].$call['type'];
if (is_array($call['args'])) {
foreach ($call['args'] as &$arg) {
get_arg($arg);
}
}
}
$ret[] = '#'.str_pad($i - $traces_to_ignore, 3, ' ')
.$object.$call['function'].'('.implode(', ', $call['args'])
.') called at ['.$call['file'].':'.$call['line'].']';
}
return implode("\n",$ret);
}
function get_arg(&$arg) {
if (is_object($arg)) {
$arr = (array)$arg;
$args = array();
foreach($arr as $key => $value) {
if (strpos($key, chr(0)) !== false) {
$key = ''; }
$args[] = '['.$key.'] => '.get_arg($value);
}
$arg = get_class($arg) . ' Object ('.implode(',', $args).')';
}
}
?>