note 97101 added to function.debug-print-backtrace

From: Date: Thu, 01 Apr 2010 12:31:43 +0000
Subject: note 97101 added to function.debug-print-backtrace
Groups: php.notes 
Request: Send a blank email to php-notes+get-167614@lists.php.net to get a copy of this message
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 = ''; // Private variable found } $args[] = '['.$key.'] => '.get_arg($value); } $arg = get_class($arg) . ' Object ('.implode(',', $args).')'; } } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 196.214.6.58 ---- Manual Page -- http://www.php.net/manual/en/function.debug-print-backtrace.php Edit -- https://master.php.net/note/edit/97101 Del: integrated -- https://master.php.net/note/delete/97101/integrated Del: useless -- https://master.php.net/note/delete/97101/useless Del: bad code -- https://master.php.net/note/delete/97101/bad+code Del: spam -- https://master.php.net/note/delete/97101/spam Del: non-english -- https://master.php.net/note/delete/97101/non-english Del: in docs -- https://master.php.net/note/delete/97101/in+docs Del: other reasons-- https://master.php.net/note/delete/97101 Reject -- https://master.php.net/note/reject/97101 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#167614) next »