Home  >  Article  >  php教程  >  How to learn PHP debug_backtrace()

How to learn PHP debug_backtrace()

黄舟
黄舟Original
2016-12-28 13:35:231480browse

Debug_backtrace function understanding 1

The function of debug_backtrace function is to generate a backtrace.

The debug_backtrace function returns an associative array.

1. How to understand backtrace;

2. Can associative arrays be understood as a new array that is related to the original array;



debug_backtrace function understanding 2

Parameters of debug_backtrace function


function: the current function name.

1. Whether the current function name is a custom function or a system function;

line: the current line number.

1. Can line be understood as the number of lines where the function is called?

file: the current file name.

1.file can be understood as the file where the current debugging is located

class: the current class name

object: the current object.

type: current call type, possible calls:

Return: "->" - method call

Return: "::" - static method call

Return nothing - function call

1. How to understand the calls of various methods;


If the args[] array is in the function, List function parameters. If in a referenced file, list the referenced file name.




##debug_backtrace function understanding 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");

?>

Output:

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 how to learn PHP debug_backtrace(). For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!



Statement:
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