The xdebug_get_function_stack Function
The xdebug_get_function_stack
function returns an array containing information about the current function call stack. Each element of the array is an associative array with data about the call. The function requires the Xdebug extension to be installed.
Syntax
xdebug_get_function_stack();
Example
A simple example of getting the call stack:
<?php
function test() {
var_dump(xdebug_get_function_stack());
}
test();
?>
Code execution result:
[
[
'function' => 'test',
'file' => '/path/to/file.php',
'line' => 4,
'params' => []
],
[
'function' => '{main}',
'file' => '/path/to/file.php',
'line' => 5,
'params' => []
]
]
Example
Example with nested function calls:
<?php
function inner() {
return xdebug_get_function_stack();
}
function outer() {
return inner();
}
$res = outer();
print_r($res);
?>
Code execution result:
[
[
'function' => 'inner',
'file' => '/path/to/file.php',
'line' => 3,
'params' => []
],
[
'function' => 'outer',
'file' => '/path/to/file.php',
'line' => 6,
'params' => []
],
[
'function' => '{main}',
'file' => '/path/to/file.php',
'line' => 8,
'params' => []
]
]
See Also
-
the
debug_backtrace
function,
which returns similar call stack information