debug_backtrace()函数生成一个回溯。它返回一个关联数组。可能返回的元素如下-
| 名称 | 类型 | 描述 |
|---|---|---|
| 功能 | 串 | 当前函数名称。 |
| 线 | 整数 | 当前行号。 |
| 文件 | 串 | 当前文件名。 |
| 类 | 串 | 当前的类名。 |
| 目的 | 串 | 当前对象。 |
| 类型 | 串 | 当前通话类型。如果方法调用,则返回“->”。如果是静态方法调用,则返回“ ::”。如果调用函数,则不返回任何内容。 |
| 精氨酸 | 数组 | 如果在函数内部,则会列出函数参数。如果在包含文件中,则列出包含的文件名。 |
debug_backtrace(options, limit)
options-以下给定选项的位掩码-
DEBUG_BACKTRACE_PROVIDE_OBJECT:是否填充“对象”索引
DEBUG_BACKTRACE_IGNORE_ARGS:是否省略“ args”索引以及所有函数/方法参数,以节省内存。
限制-限制打印的堆叠帧数
debug_backtrace()函数返回一个关联数组。上面提到了可能的返回元素。
以下是一个例子-
<?php
function display($str) {
echo "Hi: $str";
var_dump(debug_backtrace());
}
display('hello');
?>输出结果
以下是输出-
Hi: helloarray(1) {
[0]=>
array(4) {
["file"]=> string(36) "/var/www/nhooo/php/test.php"
["line"]=> int(8)
["function"]=> string(8) "printStr"
["args"]=> array(1) {
[0]=>
&string(6) "hello"
}
}
}