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

ReflectionGenerator::getFunction

PHP function Edit on GitHub ✎

(PHP 7, PHP 8)

Gets the function name of the generator

Description

ReflectionGenerator::getFunction(): ReflectionFunctionAbstract

Enables the function name of the generator to be obtained by returning a class derived from ReflectionFunctionAbstract.

Parameters Parameters

Return Values

Returns a ReflectionFunctionAbstract class. This will be ReflectionFunction for functions, or ReflectionMethod for methods.

Changelog

VersionDescription
8.4.0ReflectionGenerator::getFunction may now be called after the generator finished executing.

Examples

ReflectionGenerator::getFunction example

php
<?php

function gen()
{
    yield 1;
}

$gen = gen();

$reflectionGen = new ReflectionGenerator($gen);

var_dump($reflectionGen->getFunction());

The above example will output something similar to:

output
object(ReflectionFunction)#3 (1) {
  ["name"]=>
  string(3) "gen"
}

See Also

  • ReflectionGenerator::getThis
  • ReflectionGenerator::getTrace

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