Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

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
  
// Initializing a user-defined class Company
class Company {
    public function GFG() {
        yield 0;
    }
}
  
// Creating a generator 'A' on the above
// class Company
$A = (new Company)->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());
?>

Output:

int(0)

Program 2:




<?php
  
// Initializing a user-defined class Departments
class Departments {
    public function Coding_Department() {
        yield 0;
    }
    public function HR_Department() {
        yield 1;
    }
    public function Marketing_Department() {
        yield 2;
    }
}
  
// Creating some generators on the above
// class Departments
$A = (new Departments)->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());
?>

Output:

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

Reference: https://www.php.net/manual/en/reflectiongenerator.getexecutinggenerator.php




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!