English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP debug_backtrace() Function Usage and Example

PHP Error & Loggings Reference Manual

The debug_backtrace() function generates a backtrace trace

Syntax

array debug_backtrace(void);

Definition and Usage

It returns an associative array. The following elements may be returned:

NameTypeDescription
functionstringThe current function name.
lineintegerThe current line number.
filestringThe current file name.
classstringThe current class name.
objectobjectThe current object.
typestringThe current call type, possible calls:
  • Returns: ""-">"  - Method Call

  • Returns: "::"  - Static Method Call

  • Returns nothing - Function Call

argsarrayIf in a function, list the function parameters. If in the referenced file, list the name of the referenced file.

Parameter

NumberParameters and Description
1

void

No parameters required

Return Value

As described in the instructions, it returns an associative array.

Online Example

Here is the usage of the debug_backtrace() function-

<?php
   function printStr($str) {
      echo  "Hi:  $str";
      var_dump(debug_backtrace());
   }
   
   printStr('hello');
?>
Test to see‹/›

This will produce the following result-

Hi:  helloarray(1)  {
   [0]=>
   array(4)  {
      ["file"]=>  string(36)  "/var/www/w3codebox/php/test.php"
      ["line"]=>  int(8)
      ["function"]=>  string(8)  "printStr"
      ["args"]=>  array(1)  {
         [0]=>
         &string(6)  "hello"
      }
   }
}