(PHP 7, PHP 8)
ReflectionGenerator::getTrace — 取得執行中產生器的追蹤資訊
取得目前執行中產生器的追蹤資訊。
optionsoptions 的值可以是以下任何旗標。
| 選項 | 說明 |
|---|---|
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) {
}
}
}