首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

debug_backtrace

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

debug_backtrace - 生成回溯

描述

代码语言:javascript
复制
array debug_backtrace ([ int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT [, int $limit = 0 ]] )

debug_backtrace()生成一个 PHP 回溯。

参数

options

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

DEBUG_BACKTRACE_PROVIDE_OBJECT

Whether or not to populate the "object" index.

DEBUG_BACKTRACE_IGNORE_ARGS

Whether 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)它将返回所有堆栈帧。

返回值

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

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__

object

object

The current object.

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).

更新日志

描述

5.4.0

增加了可选的参数限制。

5.3.6

参数 provide_object 已更改为选项,并添加了附加选项 DEBUG_BACKTRACE_IGNORE_ARGS。

5.2.5

添加了可选参数 provide_object。

5.1.1

将当前对象添加为可能的返回元素。

例子

示例#1 debug_backtrace()示例

代码语言:javascript
复制
<?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 时的结果如下所示:

代码语言:javascript
复制
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() - 打印回溯

debug_print_backtrace →

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com