note 86932 added to function.debug-print-backtrace
| From: | dany dot dylan at gmail dot com | Date: | Tue, 11 Nov 2008 05:51:21 +0000 |
| Subject: | note 86932 added to function.debug-print-backtrace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146377@lists.php.net to get a copy of this message | ||
I like the output of debug_print_backtrace() but I sometimes want it as a string.
bortuzar's solution to use output buffering is great, but I'd like to factorize that into
a function. Doing that however always results in whatever function name I use appearing at the top
of the stack which is redundant.
Below is my noddy (simple) solution. If you don't care for renumbering the call stack, omit
the second preg_replace().
function debug_string_backtrace() {
ob_start();
debug_print_backtrace();
$trace = ob_get_contents();
ob_end_clean();
// Remove first item from backtrace as it's this function which
// is redundant.
$trace = preg_replace ('/^#0\s+' . __FUNCTION__ . "[^\n]*\n/", '',
$trace, 1);
// Renumber backtrace items.
$trace = preg_replace ('/^#(\d+)/me', '\'#\' . ($1 - 1)', $trace);
return $trace;
}
----
Server IP: 69.147.83.197
Probable Submitter: 122.104.173.226 (proxied: 127.0.0.1)
----
Manual Page -- http://www.php.net/manual/en/function.debug-print-backtrace.php
Edit -- https://master.php.net/note/edit/86932
Del: integrated -- https://master.php.net/note/delete/86932/integrated
Del: useless -- https://master.php.net/note/delete/86932/useless
Del: bad code -- https://master.php.net/note/delete/86932/bad+code
Del: spam -- https://master.php.net/note/delete/86932/spam
Del: non-english -- https://master.php.net/note/delete/86932/non-english
Del: in docs -- https://master.php.net/note/delete/86932/in+docs
Del: other reasons-- https://master.php.net/note/delete/86932
Reject -- https://master.php.net/note/reject/86932
Search -- https://master.php.net/manage/user-notes.php