PHP | ReflectionGenerator getThis() Function
Last Updated :
17 Dec, 2019
The ReflectionGenerator::getThis() function is an inbuilt function in PHP which is used to return the $this value of the specified generator.
Syntax:
object ReflectionGenerator::getThis ( void )
Parameters: This function does not accept any parameter.
Return Value: This function returns the $this value of the specified generator.
Below programs illustrate the ReflectionGenerator::getThis() function in PHP:
Program_1:
<?php
class Company
{
public function GFG()
{
yield 0;
}
}
$A = ( new Company)->GFG();
$B = new ReflectionGenerator( $A );
$C = $B ->getThis();
var_dump( $C );
?>
|
Output:
object(Company)#1 (0) {
}
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 ->getThis());
echo "\n" ;
var_dump( $E ->getThis());
echo "\n" ;
var_dump( $F ->getThis());
?>
|
Output:
object(Departments)#1 (0) {
}
object(Departments)#3 (0) {
}
object(Departments)#5 (0) {
}
Reference: https://www.php.net/manual/en/reflectiongenerator.getthis.php
Share your thoughts in the comments
Please Login to comment...