The debug_backtrace Function
The debug_backtrace
function returns an array containing information about the current call stack.
This includes data about called functions, the files they are in, and the lines from which the call was made.
The first parameter determines whether to limit the output, and the second - how many stack levels to skip.
Syntax
debug_backtrace([options], [limit]);
Example
A simple example of using the function to output the call stack:
<?php
function test() {
var_dump(debug_backtrace());
}
test();
?>
Code execution result:
array(1) {
[0]=>
array(4) {
["file"]=>
string(17) "/path/to/file.php"
["line"]=>
int(5)
["function"]=>
string(4) "test"
["args"]=>
array(0) {
}
}
}
Example
Using parameters to limit output:
<?php
function inner() {
var_dump(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1));
}
function outer() {
inner();
}
outer();
?>
Code execution result:
array(1) {
[0]=>
array(3) {
["file"]=>
string(17) "/path/to/file.php"
["line"]=>
int(7)
["function"]=>
string(5) "inner"
}
}