W3Schools.com

PHP debug_backtrace() Function


PHP Error Reference Complete PHP Error Reference

Definition and Usage

The debug_backtrace() function generates a backtrace.

This function displays data from the code that led up to the debug_backtrace() function.

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

Name Type Description
function string The current function name
line integer The current line number
file string The current file name
class string The current class name
object object The current object
type string The current call type. Possible calls:
  • Returns: "->"  - Method call
  • Returns: "::"  - Static method call
  • Returns nothing - Function call
args array If inside a function, this lists the functions arguments. If inside an included file, this lists the included file name

Syntax

debug_backtrace()


Example

<?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");
?>

The output of the code above should be something like this:

Array
(
[0] => Array
  (
  [file] => C:\webfolder\test.php
  [line] => 7
  [function] => three
  [args] => Array
    (
    [0] => Cleveland
    [1] => Brown
    )
  )
[1] => Array
  (
  [file] => C:\webfolder\test.php
  [line] => 3
  [function] => two
  [args] => Array
    (
    [0] => Glenn
    [1] => Quagmire
    )
  )
[2] => Array
  (
  [file] => C:\webfolder\test.php
  [line] => 14
  [function] => one
  [args] => Array
    (
    [0] => Peter
    [1] => Griffin
    )
  )
)


PHP Error Reference Complete PHP Error Reference

W3Schools Certification

W3Schools' Online Certification

The perfect solution for professionals who need to balance work, family, and career building.

More than 10 000 certificates already issued!

Get Your Certificate »

The HTML Certificate documents your knowledge of HTML.

The CSS Certificate documents your knowledge of advanced CSS.

The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.

The jQuery Certificate documents your knowledge of jQuery.

The XML Certificate documents your knowledge of XML, XML DOM and XSLT.

The ASP Certificate documents your knowledge of ASP, SQL, and ADO.

The PHP Certificate documents your knowledge of PHP and SQL (MySQL).

WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE