note 88176 added to function.debug-print-backtrace
| From: | bradley dot giesbrecht at gmail dot com | Date: | Wed, 14 Jan 2009 00:51:53 +0000 |
| Subject: | note 88176 added to function.debug-print-backtrace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-149158@lists.php.net to get a copy of this message | ||
I was using the function by dany dot dylan at gmail dot com and found that preg_replace had string
length limits. So here is yet another output format function.
if ( !function_exists ( "mydie" ) ) {
function mydie ( ) { $this_file = __FILE__ ; $this_line = __LINE__ ;
$buffer = array ( ) ;
$trace_calls = "" ;
ob_start ( ) ;
debug_print_backtrace ( ) ;
$buffer[ "0" ] = ob_get_contents ( ) ;
ob_end_clean ( ) ;
$buffer[ "0" ] = array_slice ( explode ( "#" , $buffer[ "0" ] ) , 1
, -1 , false ) ;
foreach ( $buffer[ "0" ] as $key => $value ) {
$value = explode ( ") called at [" , $value ) ;
if ( $key == 0 ) {
$value[ "0" ] = "0 " . __FUNCTION__ . "(see above vars)" ;
}
$trace_calls .= "#" . implode ( ")\n\tcalled at [" , $value ) ;
}
unset ( $buffer , $key , $value ) ;
echo "<pre>function " . __FUNCTION__ . " lives
here:{$this_file}:{$this_line}</pre>" ;
echo ( "<pre>" . print_r( func_get_args ( ) , true ) . "</pre>" )
;
if ( $trace_calls == "" ) $trace_calls = "No functions were called." ;
echo ( "<pre>" . $trace_calls . "</pre>" ) ;
die ;
}
}
function a ( ) {
b ( func_get_args ( ) , 2 ) ;
}
function b ( ) {
c ( func_get_args ( ) , 3 ) ;
}
function c ( ) {
mydie ( func_get_args ( ) , 4 ) ;
}
a ( 1 ) ;
## outputs
function mydie lives here:/path/file.php:4
Array
(
[0] => Array
(
[0] => Array
(
[0] => Array
(
[0] => 1
)
[1] => 2
)
[1] => 3
)
[1] => 4
)
#0 mydie(see above vars))
called at [/path/file.php:54]
#1 c(Array ([0] => Array ([0] => 1),[1] => 2), 3)
called at [/path/file.php:49]
#2 b(Array ([0] => 1), 2)
called at [/path/file.php:43]
----
Server IP: 209.41.74.194
Probable Submitter: 68.116.90.34
----
Manual Page -- http://www.php.net/manual/en/function.debug-print-backtrace.php
Edit -- https://master.php.net/note/edit/88176
Del: integrated -- https://master.php.net/note/delete/88176/integrated
Del: useless -- https://master.php.net/note/delete/88176/useless
Del: bad code -- https://master.php.net/note/delete/88176/bad+code
Del: spam -- https://master.php.net/note/delete/88176/spam
Del: non-english -- https://master.php.net/note/delete/88176/non-english
Del: in docs -- https://master.php.net/note/delete/88176/in+docs
Del: other reasons-- https://master.php.net/note/delete/88176
Reject -- https://master.php.net/note/reject/88176
Search -- https://master.php.net/manage/user-notes.php