PHP Conference Japan 2024

ReflectionGenerator::getTrace

(PHP 7, PHP 8)

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() 範例

<?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