PHP - Manual: ReflectionGenerator::getFunction
2024-11-12
(PHP 7, PHP 8)
ReflectionGenerator::getFunction — Gets the function name of the generator
Enables the function name of the generator to be obtained by returning a class derived from ReflectionFunctionAbstract.
此函数没有参数。
Returns a ReflectionFunctionAbstract class. This will be ReflectionFunction for functions, or ReflectionMethod for methods.
示例 #1 ReflectionGenerator::getFunction() example
<?php
function gen()
{
yield 1;
}
$gen = gen();
$reflectionGen = new ReflectionGenerator($gen);
var_dump($reflectionGen->getFunction());
以上例程的输出类似于:
object(ReflectionFunction)#3 (1) { ["name"]=> string(3) "gen" }
官方地址:https://www.php.net/manual/en/reflectiongenerator.getfunction.php