📜  PHP | ReflectionGenerator getExecutingLine()函数

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

PHP | ReflectionGenerator getExecutingLine()函数

ReflectionGenerator::getExecutingLine()函数是PHP中的一个内置函数,用于返回生成器中当前正在执行的指定语句的行号。

句法:

int ReflectionGenerator::getExecutingLine( void )

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

返回值:该函数返回生成器中当前正在执行的指定语句的行号。

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

方案一:

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;
?>

输出:

8

方案二:

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();
?>
输出:
8
12
16

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