note 88176 modified in function.debug-print-backtrace by danbrown
| From: | danbrown@php.net | Date: | Wed, 14 Jan 2009 01:02:08 +0000 |
| Subject: | note 88176 modified in function.debug-print-backtrace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149159@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.
<?php
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]
--was--
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]
http://php.net/manual/en/function.debug-print-backtrace.php