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

phpxdebug_get_function_stack();

Example

A simple example of getting the call stack:

php<?php
  function test() {
    var_dump(xdebug_get_function_stack());
  }
  test();
?>

Code execution result:

php[
  [
    '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<?php
  function inner() {
    return xdebug_get_function_stack();
  }
  function outer() {
    return inner();
  }
  $res = outer();
  print_r($res);
?>

Code execution result:

php[
  [
    '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