Funktionen xdebug_get_function_stack

Funktionen xdebug_get_function_stack returnerer et array, der indeholder information om den aktuelle kaldstak af funktioner. Hvert element i arrayet er et associativt array med data om kaldet. For at funktionen skal virke, kræves den installerede Xdebug-udvidelse.

Syntaks

phpxdebug_get_function_stack();

Eksempel

Simpelt eksempel på at hente kaldstakken:

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

Resultat af kodekørsel:

php[
  [
    'function' => 'test',
    'file' => '/path/to/file.php',
    'line' => 4,
    'params' => []
  ],
  [
    'function' => '{main}',
    'file' => '/path/to/file.php',
    'line' => 5,
    'params' => []
  ]
]

Eksempel

Eksempel med indlejrede funktionskald:

php<?php
  function inner() {
    return xdebug_get_function_stack();
  }
  function outer() {
    return inner();
  }
  $res = outer();
  print_r($res);
?>

Resultat af kodekørsel:

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' => []
  ]
]

Se også

  • funktionen debug_backtrace,
    som returnerer lignende information om kaldstakken