The debug_backtrace() function generates a backtrace. It returns an associative array. The possible returned elements are as follows −
| Name | Type | Description |
|---|---|---|
| function | string | The current function name. |
| line | integer | The current line number. |
| file | string | The current file name. |
| class | string | The current class name. |
| object | string | The current Object. |
| type | string | The current call type. If a method call, "->" is returned. If a static method call, "::" is returned. If a function call, nothing is returned. |
| arg | array | If inside a function, this lists the functions arguments. If inside an included file, this lists the included file name(s). |
Syntax
debug_backtrace(options, limit)
Parameters
options − A bitmask for the below given options −
- DEBUG_BACKTRACE_PROVIDE_OBJECT: Whether or not to populate the "object" index
- DEBUG_BACKTRACE_IGNORE_ARGS: Whether or not to omit the "args" index, and all the function/method arguments, to save memory.
limit − Limit the number of stack frames printed
Return
The debug_backtrace() function returns an associative array. The possible returned elements are mentioned above.
Example
The following is an example −
<?php
function display($str) {
echo "Hi: $str";
var_dump(debug_backtrace());
}
display('hello');
?>Output
The following is the output −
Hi: helloarray(1) {
[0]=>
array(4) {
["file"]=> string(36) "/var/www/tutorialspoint/php/test.php"
["line"]=> int(8)
["function"]=> string(8) "printStr"
["args"]=> array(1) {
[0]=>
&string(6) "hello"
}
}
}