array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'reflectiongenerator.getthis.php', 1 => 'ReflectionGenerator::getThis', ), 'up' => array ( 0 => 'class.reflectiongenerator.php', 1 => 'ReflectionGenerator', ), 'prev' => array ( 0 => 'reflectiongenerator.getfunction.php', 1 => 'ReflectionGenerator::getFunction', ), 'next' => array ( 0 => 'reflectiongenerator.gettrace.php', 1 => 'ReflectionGenerator::getTrace', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/reflection/reflectiongenerator/getthis.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 7, PHP 8)
ReflectionGenerator::getThis — ジェネレータの $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) { }