In PHP, debug_print_backtrace() prints the list of function calls that led to the current line, one call per line. It sends the text straight to the output.
It does the same job as debug_backtrace(), but instead of giving you an array it prints a ready-to-read report. It is a quick way to answer the question: how did my code get here? Because it prints, it returns nothing.
Syntax
Call debug_print_backtrace() with the values you need. Start with this line.
PHP
debug_print_backtrace();
Call
What it does
debug_print_backtrace()
Prints every active call, including the arguments.
The printed lines contain file paths and line numbers, so they look different on every computer. To capture the text instead of showing it, wrap the call in ob_start() and ob_get_clean().
Library declarations
PHP
debug_print_backtrace(int $options = 0, int $limit = 0): void
Parameters
Parameter
Description
options
Optional. A bitmask. Use DEBUG_BACKTRACE_IGNORE_ARGS to leave out the argument values. The default is 0, which prints the arguments.
limit
Optional. The maximum number of calls to print. The default is 0, which means no limit.
Return Value
Return Value
Description
void
Nothing is returned. The backtrace is printed to the output instead.
PHP Examples
Example 1 — Capturing the Printed Backtrace
The real text contains file paths, so this example captures it with output buffering and then describes it.
Default shows the value: yes
IGNORE_ARGS shows the value: no
How It Works
Both functions receive the same string, secret-value.
showWithArgs() prints the backtrace with default options, so the string is part of the printed line.
showWithoutArgs() passes DEBUG_BACKTRACE_IGNORE_ARGS, so no argument values are printed.
str_contains() checks each captured text, and only the first one contains the word.
Frequently Asked Questions
It prints the list of function calls that led to the current line. Each call gets its own numbered line, starting with #0 for the most recent call.
No. It returns void and prints directly. If you need the text as a string, wrap the call in ob_start() and ob_get_clean(). If you need structured data, use debug_backtrace() instead.
Pass DEBUG_BACKTRACE_IGNORE_ARGS as the first argument. The calls are still listed, but the values that were passed in are left out.
Each line includes the full path of your file and the line number, and the exact layout has changed slightly between PHP versions. The idea is always the same: one line per active call.
No. It is a debugging helper and it can show private data. Remove it before publishing, or send backtraces to a log file with error_log() instead of printing them to visitors.