PHP debug_backtrace() 函数
定义和用法
debug_backtrace() 函数生成 backtrace(回溯跟踪)。
该函数显示由 debug_backtrace() 函数代码生成的数据。
返回一个关联数组。可能返回的元素如下:
| 名称 | 类型 | 描述 |
|---|---|---|
| function | string | 当前函数名称 |
| line | integer | 当前行号 |
| file | string | 当前文件名 |
| class | string | 当前类名 |
| object | object | 当前对象 |
| type | string |
当前调用类型。可能的调用:
|
| args | array | 如果在函数中,列出函数参数。如果在被引用的文件中,列出被引用的文件名。 |
实例
生成 PHP backtrace:
<?php
function a($txt) {
b("Glenn");
}
function b($txt) {
c("Cleveland");
}
function c($txt) {
var_dump(debug_backtrace());
}
a("Peter");
?>
以上代码的输出类似这样:
Array (
[0] => Array (
[file] => C:\webfolder\test.php
[line] => 6
[function] => c
[args] => Array (
[0] => Cleveland
)
)
[1] => Array (
[file] => C:\webfolder\test.php
[line] => 3
[function] => b
[args] => Array (
[0] => Glenn
)
)
[2] => Array (
[file] => C:\webfolder\test.php
[line] => 11
[function] => a
[args] => Array (
[0] => Peter
)
)
)
语法
debug_backtrace(options,limit);
| 参数 | 描述 |
|---|---|
| options |
可选。规定以下选项的位掩码:
|
| limit | 可选。限制返回堆栈帧的数量。默认为 (limit=0) ,返回所有的堆栈帧。 |
技术细节
| 返回值: | None |
|---|---|
| PHP 版本: | 4.3+ |
| PHP 更新日志 |
PHP 5.4:添加了可选的参数 limit。 PHP 5.3.6:参数 provide_object 改成 options,并且增加了可选参数 DEBUG_BACKTRACE_IGNORE_ARGS。 PHP 5.2.5:添加了可选参数 provide_object。 PHP 5.1.1:添加了当前的 object 为可能返回的元素。 |