📜  PHP | ReflectionGenerator getExecutingGenerator()函数

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

PHP | ReflectionGenerator getExecutingGenerator()函数

ReflectionGenerator::getExecutingGenerator()函数是PHP中的一个内置函数,用于返回当前正在执行的 Generator 对象。

句法:

Generator ReflectionGenerator::getExecutingGenerator( void )

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

返回值:该函数返回当前正在执行的 Generator 对象。

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

方案一:

GFG();
  
// Using ReflectionGenerator over the 
// above generator 'A'
$B = new ReflectionGenerator($A);
  
// Calling the getExecutingGenerator() function
$C = $B->getExecutingGenerator();
  
// Getting the currently executing
// Generator object
var_dump($C->current());
?>

输出:

int(0)

方案二:

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 getExecutingGenerator() function
// and getting the currently executing
// Generator object
var_dump($D->getExecutingGenerator()->current());
var_dump($E->getExecutingGenerator()->current());
var_dump($F->getExecutingGenerator()->current());
?>

输出:

int(0)
int(1)
int(2)

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