ReflectionGenerator::getTrace
(PHP 7)
ReflectionGenerator::getTrace — 実行中のジェネレータのトレースを取得する
説明
public ReflectionGenerator::getTrace
([ int $options
= DEBUG_BACKTRACE_PROVIDE_OBJECT
] ) : array
現在実行中のジェネレータのトレースを取得します。
パラメータ
options
options
の値は以下のフラグのうちのいずれかです:利用可能なオプション オプション 説明 DEBUG_BACKTRACE_PROVIDE_OBJECT
デフォルト DEBUG_BACKTRACE_IGNORE_ARGS
スタックトレース内の関数に引数の情報を含めない
返り値
現在実行中のジェネレータのトレースを返します。
例
例1 ReflectionGenerator::getTrace() の例
<?phpfunction 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) { } } }
参考
- ReflectionGenerator::getFunction() - ジェネレータの関数名を取得する
- ReflectionGenerator::getThis() - ジェネレータの $this の値を取得する