The debug_print_backtrace Function
The debug_print_backtrace
function outputs information about the current call stack - the sequence of functions that led to the current point of execution. The function does not return a value but outputs the result immediately. The first parameter can specify flags to change the output format, the second - a limit on the number of output levels.
Syntax
debug_print_backtrace(int $options = 0, int $limit = 0): void
Example
A simple example of calling the function:
<?php
function a() {
b();
}
function b() {
debug_print_backtrace();
}
a();
?>
Code execution result:
#0 b() called at [test.php:4]
#1 a() called at [test.php:8]
Example
Using the limit
parameter to limit the output:
<?php
function x() {
y();
}
function y() {
z();
}
function z() {
debug_print_backtrace(0, 2);
}
x();
?>
Code execution result:
#0 z() called at [test.php:9]
#1 y() called at [test.php:6]
Example
Using options to change the output format:
<?php
function test1() {
test2();
}
function test2() {
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
}
test1();
?>
Code execution result (without function arguments):
#0 test2() called at [test.php:4]
#1 test1() called at [test.php:8]
See Also
-
the
debug_backtrace
function,
which returns a stack trace as an array -
the
error_reporting
function,
which sets the error reporting level