Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

debug_backtrace

Returns the chain of calls that led to the current point.

Syntax

debug_backtrace(int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT, int $limit = 0): array

Parameters

ParameterTypeDescription
$optionsintOptional. Which details to include.
$limitintOptional. How many levels to return.

Return value

arrayAn array of calls: function, file, line.

Examples

Who called the function:

<?php
 
function save(): string
{
    return implode(' <- ', array_column(debug_backtrace(), 'function'));
}
 
function handleForm(): string
{
    return save();
}
 
echo handleForm();

Output:

save <- handleForm

Notes

For a caught exception the getTraceAsString() method returns the same chain.

See also

  • var_dump — Prints the type and the value — for debugging.
  • error_log — Writes a message to the error log.
  • Throwable — The common interface of everything that can be thrown and caught.

In the tutorial

  • Errors and debugging — The kinds of PHP errors, error display settings, the log, turning warnings into exceptions and debugging techniques.

Thanks for reading!

Donate to the site — we work hard for you.