Open In App

PHP | ReflectionGenerator getExecutingLine() Function

Last Updated : 20 Dec, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The ReflectionGenerator::getExecutingLine() function is an inbuilt function in PHP which is used to return the line number of the specified currently executing statement in the generator. Syntax:
int ReflectionGenerator::getExecutingLine( void )
Parameters: This function does not accept any parameters. Return Value: This function returns the line number of the specified currently executing statement in the generator. Below programs illustrate the ReflectionGenerator::getExecutingLine() function in PHP: Program 1: php
<?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 getExecutingLine() function
$C = $B->getExecutingLine();

// Getting the line number of the specified
// currently executing statement in 
// the generator 'A'
echo $C;
?>
Output:
8
Program 2: php
<?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 getExecutingLine() function
// and getting the line number of the specified
// currently executing statement in 
// the generators
echo $D->getExecutingLine();
echo "\n";
echo $E->getExecutingLine();
echo "\n";
echo $F->getExecutingLine();
?>
Output:
8
12
16
Reference: https://www.php.net/manual/en/reflectiongenerator.getexecutingline.php

Next Article

Similar Reads