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): arrayParameters
| Parameter | Type | Description |
|---|---|---|
| $options | int | Optional. Which details to include. |
| $limit | int | Optional. 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 <- handleFormNotes
For a caught exception the getTraceAsString() method returns the same chain.
See also
In the tutorial
- Errors and debugging — The kinds of PHP errors, error display settings, the log, turning warnings into exceptions and debugging techniques.