ReflectionGenerator::getTrace

(PHP 7, PHP 8)

ReflectionGenerator::getTrace実行中のジェネレータのトレースを取得する

説明

publicReflectionGenerator::getTrace(int$options = DEBUG_BACKTRACE_PROVIDE_OBJECT): array

現在実行中のジェネレータのトレースを取得します。

パラメータ

options

options の値は以下のフラグのうちのいずれかです:

利用可能なオプション
オプション説明
DEBUG_BACKTRACE_PROVIDE_OBJECT デフォルト
DEBUG_BACKTRACE_IGNORE_ARGS スタックトレース内の関数に引数の情報を含めない

戻り値

現在実行中のジェネレータのトレースを返します。

例1 ReflectionGenerator::getTrace() の例

<?php
function foo() {
yield
1;
}

function
bar()
{
yield from
foo();
}

function
baz()
{
yield from
bar();
}

$gen = baz();
$gen->valid(); // ジェネレータを開始

var_dump((new ReflectionGenerator($gen))->getTrace());

上の例の出力は、 たとえば以下のようになります。

array(2) { [0]=> array(4) { ["file"]=> string(18) "example.php" ["line"]=> int(8) ["function"]=> string(3) "foo" ["args"]=> array(0) { } } [1]=> array(4) { ["file"]=> string(18) "example.php" ["line"]=> int(12) ["function"]=> string(3) "bar" ["args"]=> array(0) { } } }

参考

To Top