|
|
 |
debug_backtrace (PHP 4 >= 4.3.0, PHP 5) debug_backtrace --
Generates a backtrace
Descriptionarray debug_backtrace ( void )
debug_backtrace() generates a PHP backtrace
and returns this information as an associative array. The
possible returned elements are listed in the following table:
表格 1. Possible returned elements from debug_backtrace() | Name | Type | Description |
|---|
| function | string |
The current function name. See also
__FUNCTION__.
| | line | integer |
The current line number. See also
__LINE__.
| | file | string |
The current file name. See also
__FILE__.
| | class | string |
The current class name. See also
__CLASS__
| | type | string |
The current call type. If a method call, "->" is returned. If a static
method call, "::" is returned. If a function call, nothing is returned.
| | args | array |
If inside a function, this lists the functions arguments. If
inside an included file, this lists the included file name(s).
|
The following is a simple example.
例子 1.
debug_backtrace() example
|
<?php
// filename: a.php
function a_test($str)
{
echo "\nHi: $str";
var_dump(debug_backtrace());
}
a_test('friend');
?>
<?php
// filename: b.php
include_once '/tmp/a.php';
?>
|
Results when executing /tmp/b.php:
Hi: friend
array(2) {
[0]=>
array(4) {
["file"] => string(10) "/tmp/a.php"
["line"] => int(10)
["function"] => string(6) "a_test"
["args"]=>
array(1) {
[0] => &string(6) "friend"
}
}
[1]=>
array(4) {
["file"] => string(10) "/tmp/b.php"
["line"] => int(2)
["args"] =>
array(1) {
[0] => string(10) "/tmp/a.php"
}
["function"] => string(12) "include_once"
}
} |
|
See also trigger_error() and
debug_print_backtrace().
jlim#natsoft.com.my
13-Mar-2003 09:51
Pretty print the backtrace(). Functions are indented based on call value,
and file is linked using file:// for convenience.
Enjoy, John
Lim
function adodb_backtrace($print=true) { $s =
''; if (PHPVERSION() >= 4.3) { $MAXSTRLEN =
64; $s = '<pre align=left>'; $traceArr =
debug_backtrace(); array_shift($traceArr); $tabs =
sizeof($traceArr)-1; foreach ($traceArr as $arr) { for ($i=0;
$i < $tabs; $i++) $s .= ' '; $tabs -= 1; $s .=
'<font face="Courier New,Courier">'; if
(isset($arr['class'])) $s .= $arr['class'].'.'; foreach($arr['args']
as $v) { if (is_null($v)) $args[] = 'null'; else if
(is_array($v)) $args[] = 'Array['.sizeof($v).']'; else if
(is_object($v)) $args[] = 'Object:'.get_class($v); else if
(is_bool($v)) $args[] = $v ? 'true' : 'false'; else { $v
= (string) @$v; $str =
htmlspecialchars(substr($v,0,$MAXSTRLEN)); if (strlen($v) >
$MAXSTRLEN) $str .= '...'; $args[] =
$str; } } $s .=
$arr['function'].'('.implode(', ',$args).')'; $s .=
sprintf("</font><font color=#808080 size=-1> # line
%4d,". " file: <a
href=\"file:/%s\">%s</a></font>",
$arr['line'],$arr['file'],$arr['file']); $s .=
"\n"; } $s .= '</pre>'; if ($print)
print $s; } return $s; }
| |