debug_backtrace
产生一条回溯跟踪(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) ,返回所有的堆栈帧。 |