在线文档教程
PHP

debug_backtrace

debug_backtrace

(PHP 4 >= 4.3.0, PHP 5, PHP 7)

debug_backtrace - 生成回溯

描述

array debug_backtrace ([ int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT [, int $limit = 0 ]] )

debug_backtrace()生成一个 PHP 回溯。

参数

options

从5.3.6开始,此参数是以下选项的位掩码:

DEBUG_BACKTRACE_PROVIDE_OBJECTWhether or not to populate the "object" index.
DEBUG_BACKTRACE_IGNORE_ARGSWhether or not to omit the "args" index, and thus all the function/method arguments, to save memory.

在5.3.6之前,唯一确认的值是TRUEFALSE,分别与设置或不设置DEBUG_BACKTRACE_PROVIDE_OBJECT选项相同。 limit

从5.4.0开始,此参数可用于限制返回的堆栈帧数。默认情况下(limit= 0)它将返回所有堆栈帧。

返回值

返回关联数组的数组。可能的返回元素如下所示:

NameTypeDescription
functionstringThe current function name. See also __FUNCTION__.
lineintegerThe current line number. See also __LINE__.
filestringThe current file name. See also __FILE__.
classstringThe current class name. See also __CLASS__
objectobjectThe current object.
typestringThe current call type. If a method call, "->" is returned. If a static method call, "::" is returned. If a function call, nothing is returned.
argsarrayIf inside a function, this lists the functions arguments. If inside an included file, this lists the included file name(s).

更新日志

描述
5.4.0增加了可选的参数限制。
5.3.6参数 provide_object 已更改为选项,并添加了附加选项 DEBUG_BACKTRACE_IGNORE_ARGS。
5.2.5添加了可选参数 provide_object。
5.1.1将当前对象添加为可能的返回元素。

例子

示例#1 debug_backtrace()示例

<?php // filename: /tmp/a.php function a_test($str) {     echo "\nHi: $str";     var_dump(debug_backtrace() } a_test('friend' ?> <?php // filename: /tmp/b.php include_once '/tmp/a.php'; ?>

执行 /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" } }

  • trigger_error() - 生成用户级错误/警告/通知消息

  • debug_print_backtrace() - 打印回溯

← Error Handling Functions

debug_print_backtrace →