📜  PHP |反射生成器 getFunction()函数

📅  最后修改于: 2022-05-13 01:56:38.873000             🧑  作者: Mango

PHP |反射生成器 getFunction()函数

ReflectionGenerator::getFunction()函数是PHP中的一个内置函数,用于返回指定生成器的函数名。

句法:

ReflectionFunctionAbstract ReflectionGenerator::getFunction ( void )

参数:此函数不接受任何参数。

返回值:该函数返回指定生成器的函数名。

下面的程序说明了PHP中的ReflectionGenerator::getFunction()函数
程序_1:

GFG();
  
// Using ReflectionGenerator over the 
// above generator 'A'
$B = new ReflectionGenerator($A);
  
// Calling the getFunction() function
$C = $B->getFunction();
  
// Getting the function name of the
// specified generator 'A'
var_dump($C);
?>

输出:

object(ReflectionMethod)#4 (2) {
  ["name"]=>
  string(3) "GFG"
  ["class"]=>
  string(7) "Company"
}

程序_2:

Coding_Department();
$B = (new Departments)->HR_Department();
$C = (new Departments)->Marketing_Department();
  
// Using ReflectionGenerator over the 
// above generators
$D = new ReflectionGenerator($A);
$E = new ReflectionGenerator($B);
$F = new ReflectionGenerator($C);
  
// Calling the getFunction() function
// and getting the function name of the
// specified generators
var_dump($D->getFunction());
echo "\n";
var_dump($E->getFunction());
echo "\n";
var_dump($F->getFunction());
?>

输出:

object(ReflectionMethod)#10 (2) {
  ["name"]=>
  string(17) "Coding_Department"
  ["class"]=>
  string(11) "Departments"
}

object(ReflectionMethod)#10 (2) {
  ["name"]=>
  string(13) "HR_Department"
  ["class"]=>
  string(11) "Departments"
}

object(ReflectionMethod)#10 (2) {
  ["name"]=>
  string(20) "Marketing_Department"
  ["class"]=>
  string(11) "Departments"
}

参考: https://www. PHP.net/manual/en/reflectiongenerator.getfunction。 PHP