関数 debug_print_backtrace
関数 debug_print_backtrace は、現在の実行ポイントに至るまでの関数呼び出しの順序である、現在の呼び出しスタックに関する情報を出力します。この関数は値を返さず、結果を直接出力します。第一引数で出力形式を変更するためのフラグを、第二引数で出力するレベルの数の制限を指定できます。
構文
debug_print_backtrace(int $options = 0, int $limit = 0): void
例
関数呼び出しの簡単な例:
<?php
function a() {
b();
}
function b() {
debug_print_backtrace();
}
a();
?>
コードの実行結果:
#0 b() called at [test.php:4]
#1 a() called at [test.php:8]
例
出力を制限するための limit パラメータの使用:
<?php
function x() {
y();
}
function y() {
z();
}
function z() {
debug_print_backtrace(0, 2);
}
x();
?>
コードの実行結果:
#0 z() called at [test.php:9]
#1 y() called at [test.php:6]
例
出力形式を変更するためのオプションの使用:
<?php
function test1() {
test2();
}
function test2() {
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
}
test1();
?>
コードの実行結果(関数の引数なし):
#0 test2() called at [test.php:4]
#1 test1() called at [test.php:8]
関連項目
-
関数
debug_backtrace,
スタックトレースを配列として返す関数 -
関数
error_reporting,
エラーレポートレベルを設定する関数