Current Location: Home> Function Categories> debug_backtrace

debug_backtrace

Generate a backtrace
Name:debug_backtrace
Category:Error handling
Programming Language:php
One-line Description:Generate backtrace.

Definition and usage

debug_backtrace() function generates a backtrace (backtrace trace).

This function displays the data generated by debug_backtrace() function code.

Returns an associative array. The possible returned elements are as follows:

name type describe
function string Current function name
line integer Current line number
file string Current file name
class string Current class name
object object Current object
type string

The current call type. Possible calls:

  • Return: "->" - Method Call
  • Return: "::" - Static method call
  • Return nothing - function call
args array If in a function, list the function parameters. If in the referenced file, list the referenced file name.

Example

Generate PHP backtrace:

 <?php
 function a ( $txt ) {
     b ( "Glenn" ) ;
 }
 function b ( $txt ) {
     c ( "Cleveland" ) ;
}
 function c ( $txt ) {
     var_dump ( debug_backtrace ( ) ) ;
 }
 a ( "Peter" ) ;
 ?> 

The output of the above code is similar to this:

 Array (
     [0] => Array (
         [file] => C:\webfolder\test.php
         [line] => 6
         [function] => c
         [args] => Array (
             [0] => Cleveland
         )
     )
     [1] => Array (
         [file] => C:\webfolder\test.php
         [line] => 3
         [function] => b
         [args] => Array (
             [0] => Glenn
         )
     )
     [2] => Array (
         [file] => C:\webfolder\test.php
         [line] => 11
         [function] => a
         [args] => Array (
             [0] => Peter
         )
     )
 )

grammar

 debug_backtrace ( options , limit ) ;
parameter describe
options

Optional. Specify the bitmask for the following options:

  • DEBUG_BACKTRACE_PROVIDE_OBJECT (whether to fill the index of "object")
  • DEBUG_BACKTRACE_IGNORE_ARGS (Whether to ignore the index of "args" and include all function/method parameters, it can save memory overhead.)
limit Optional. Limits the number of returned stack frames. The default is ( limit = 0), returning all stack frames.
Similar Functions
Popular Articles