What does the php debug_backtrace() function do?

怪我咯
Release: 2023-03-13 11:54:01
Original
1336 people have browsed it

定义和用法

PHP debug_backtrace() 函数生成一个 backtrace(回溯信息)。

该函数返回一个关联数组。下面是可能返回的元素:

名称 类型 描述
function 字符串 当前的函数名。
line 整数 当前的行号。
file 字符串 当前的文件名。
class 字符串 当前的类名
object 对象 当前对象。
type 字符串 当前的调用类型,可能的调用:
  • 返回: "->"  - 方法调用

  • 返回: "::"  - 静态方法调用

  • 返回 nothing - 函数调用

args 数组 如果在函数中,列出函数参数。如果在被引用的文件中,列出被引用的文件名。

语法

debug_backtrace()

例子

<?php
function one($str1, $str2) {
	two("Glenn", "Quagmire");
}

function two($str1, $str2) {
	three("Cleveland", "Brown");
}

function three($str1, $str2) {
	print_r(debug_backtrace());
}

one("Peter", "Griffin");
Copy after login

输出:

Array
(
    [0] => Array
        (
            [file] => D:\PHP\xampp\htdocs\52php\123\789.php
            [line] => 7
            [function] => three
            [args] => Array
                (
                    [0] => Cleveland
                    [1] => Brown
                )

        )

    [1] => Array
        (
            [file] => D:\PHP\xampp\htdocs\52php\123\789.php
            [line] => 3
            [function] => two
            [args] => Array
                (
                    [0] => Glenn
                    [1] => Quagmire
                )

        )

    [2] => Array
        (
            [file] => D:\PHP\xampp\htdocs\52php\123\789.php
            [line] => 14
            [function] => one
            [args] => Array
                (
                    [0] => Peter
                    [1] => Griffin
                )

        )

)
Copy after login

debug_backtrace函数理解1

debug_backtrace函数的作用为生成一个 backtrace。

debug_backtrace函数返回一个关联数组。

1.backtrace如何理解;

2.关联数组是否可以理解为可以新数组与原数组有联系;

debug_backtrace函数理解2

debug_backtrace函数的参数

function:当前的函数名。

1.当前的函数名是否为自定义的函数或者系统函数;

line:当前的行号。

1.line是否可以理解为调用函数所在的行数;

file:当前的文件名。

1.file可以理解为当前调试所在的文件

class:当前的类名

object:当前的对象。

type:当前的调用类型,可能的调用:

返回: "->" - 方法调用

返回: "::" - 静态方法调用

返回 nothing - 函数调用

1.各类方法的调用如何理解;

args[]数组如果在函数中,列出函数参数。如果在被引用的文件中,列出被引用的文件名。

debug_backtrace函数理解3

<?php 
function one($str1, $str2) { 
 two("Glenn", "Quagmire"); 
 } 
function two($str1, $str2) { 
 three("Cleveland", "Brown"); 
 } 
function three($str1, $str2) { 
 print_r(debug_backtrace()); 
 } 
 one("Peter", "Griffin"); 
?>
Copy after login

输出:

Array ( [0] => Array ( [file] => C:\wamp\www\web.php [line] => 89 [function] => three [args] => Array ( [0] => Cleveland [1] => Brown ) ) [1] => Array ( [file] => C:\wamp\www\web.php [line] => 86 [function] => two [args] => Array ( [0] => Glenn [1] => Quagmire ) ) [2] => Array ( [file] => C:\wamp\www\web.php [line] => 94 [function] => one [args] => Array ( [0] => Peter [1] => Griffin ) ) ) 

The above is the detailed content of What does the php debug_backtrace() function do?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!