php8.5
Home/ Manual/ reflection / reflectiongenerator/ ReflectionGenerator::getThis

ReflectionGenerator::getThis

PHP function Edit on GitHub ✎

(PHP 7, PHP 8)

Gets the $this value of the generator

Description

ReflectionGenerator::getThis(): object|null

Get the $this value that the generator has access to.

Parameters Parameters

Return Values

Returns the $this value, or null if the generator was not created in a class context.

Examples

ReflectionGenerator::getThis example

php
<?php

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

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

$reflectionGen = new ReflectionGenerator($gen);

var_dump($reflectionGen->getThis());

The above example will output something similar to:

output
object(GenExample)#3 (0) {
}

See Also

  • ReflectionGenerator::getFunction
  • ReflectionGenerator::getTrace

Source: reference/reflection/reflectiongenerator/getthis.xml · from the official PHP manual (php/doc-en)