Example
Generate a PHP backtrace:
<?php
function a($txt) {
b("Glenn");
}
function b($txt) {
c("Cleveland");
}
function c($txt) {
var_dump(debug_backtrace());
}
a("Peter");
?>
The above code will output something like 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
)
)
)
Definition and Usage
The debug_backtrace() function generates a PHP backtrace.
This function displays data from the code that led up to the debug_backtrace() function.
Returns an array of associative arrays. The possible returned elements are:
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:
|
args | array | If inside a function, it lists the functions arguments. If inside an included file, it lists the included file names |
Syntax
debug_backtrace(options,limit);
Parameter | Description |
---|---|
options |
Optional. Specifies a bitmask for the following options: |
limit | Optional. Limits the number of stack frames printed. By default (limit=0) it prints all stack frames |
Technical Details
Return Value: | None |
---|---|
PHP Version: | 4.3+ |
PHP Changelog: | PHP 5.4: The optional parameter limit was added PHP 5.3.6: The parameter provide_object was changed to options and additional option DEBUG_BACKTRACE_IGNORE_ARGS is added PHP 5.2.5: The optional parameter provide_object was added PHP 5.1.1: Added the current object as a possible return element |
< PHP Error Reference