PHP Conference Japan 2024

ReflectionGenerator::getThis

(PHP 7, PHP 8)

ReflectionGenerator::getThis取得產生器的 $this

說明

public ReflectionGenerator::getThis(): ?object

取得產生器可存取的 $this 值。

參數

此函式沒有參數。

回傳值

回傳 $this 值,如果產生器不是在類別上下文中建立的,則回傳 null

範例

範例 #1 ReflectionGenerator::getThis() 範例

<?php

class GenExample
{
public function
gen()
{
yield
1;
}
}

$gen = (new GenExample)->gen();

$reflectionGen = new ReflectionGenerator($gen);

var_dump($reflectionGen->getThis());

上述範例將輸出類似以下的內容:

object(GenExample)#3 (0) {
}

另請參閱

新增註釋

使用者貢獻的註釋

此頁面沒有使用者貢獻的註釋。
To Top