📜  PHP |反射生成器 getThis()函数

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

PHP |反射生成器 getThis()函数

ReflectionGenerator::getThis()函数是PHP中的一个内置函数,用于返回指定生成器的$this值。

句法:

object ReflectionGenerator::getThis ( void )

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

返回值:此函数返回指定生成器的$this值。

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

GFG();
  
// Using ReflectionGenerator over the 
// above generator 'A'
$B = new ReflectionGenerator($A);
  
// Calling the getThis() function
$C = $B->getThis();
  
// Getting the $this value of the
// specified generator 'A'
var_dump($C);
?>

输出:

object(Company)#1 (0) {
}

程序_2:

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 getThis() function
// and getting the $this value of the
// specified generators
var_dump($D->getThis());
echo "\n";
var_dump($E->getThis());
echo "\n";
var_dump($F->getThis());
?>

输出:

object(Departments)#1 (0) {
}

object(Departments)#3 (0) {
}

object(Departments)#5 (0) {
}

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