PHP | ReflectionGenerator getExecutingGenerator() Function
Last Updated :
20 Dec, 2019
The ReflectionGenerator::getExecutingGenerator() function is an inbuilt function in PHP which is used to return the currently executing Generator object.
Syntax:
Generator ReflectionGenerator::getExecutingGenerator( void )
Parameters: This function does not accept any parameters.
Return Value: This function returns the currently executing Generator object.
Below programs illustrate the ReflectionGenerator::getExecutingGenerator() function in PHP:
Program 1:
<?php
class Company {
public function GFG() {
yield 0;
}
}
$A = ( new Company)->GFG();
$B = new ReflectionGenerator( $A );
$C = $B ->getExecutingGenerator();
var_dump( $C ->current());
?>
|
Program 2:
<?php
class Departments {
public function Coding_Department() {
yield 0;
}
public function HR_Department() {
yield 1;
}
public function Marketing_Department() {
yield 2;
}
}
$A = ( new Departments)->Coding_Department();
$B = ( new Departments)->HR_Department();
$C = ( new Departments)->Marketing_Department();
$D = new ReflectionGenerator( $A );
$E = new ReflectionGenerator( $B );
$F = new ReflectionGenerator( $C );
var_dump( $D ->getExecutingGenerator()->current());
var_dump( $E ->getExecutingGenerator()->current());
var_dump( $F ->getExecutingGenerator()->current());
?>
|
Output:
int(0)
int(1)
int(2)
Reference: https://www.php.net/manual/en/reflectiongenerator.getexecutinggenerator.php
Share your thoughts in the comments
Please Login to comment...