Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

debug_backtrace()

Example

Produce a PHP backtrace:

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

Definition and Usage

The debug_backtrace() function creates a PHP backtrace, showing data about the code execution leading up to the point where debug_backtrace() is called. It returns an array of associative arrays, with the following possible elements:

Name

Type

Description

function

string

The name of the current function

line

integer

The line number of the current execution

file

string

The name of the current file

class

string

The name of the current class

object

object

The current instance

type

string

The type of the current call. Possible values include:

  • “->” for method calls
  • “::” for static method calls
  • No value for function calls

args

array

If within a function, it lists the function’s arguments. If within an included file, it lists the names of the included files.

Syntax

debug_backtrace(options, limit);

Parameter Values

 

Parameter

Description

options

Optional. Allows you to specify a bitmask for the following options:

  • DEBUG_BACKTRACE_PROVIDE_OBJECT (Determines whether to include the “object” index)
  • DEBUG_BACKTRACE_IGNORE_ARGS (Determines whether to exclude the “args” index and function/method arguments to conserve memory)

limit

Optional. Restricts the number of stack frames displayed. By default (when limit=0), it shows all stack frames.

Technical Details

Return Value:

An array of associative arrays

PHP Version:

4.3+

PHP Changelog:

  PHP 5.4: Introduced the optional limit parameter.

  PHP 5.3.6: Changed the provide_object parameter to options and added the DEBUG_BACKTRACE_IGNORE_ARGS option.

  PHP 5.2.5: Added the optional provide_object parameter.

  PHP 5.1.1: Included the current object as a possible return element.