PHP | ReflectionGenerator getTrace() Function
Last Updated :
26 Dec, 2022
The ReflectionGenerator::getTrace() function is an inbuilt function in PHP which is used to return the trace of the specified currently executing generator. Syntax:
array ReflectionGenerator::getTrace ( void )
Parameters: This function does not accept any parameter. Return Value: This function returns the trace of the specified currently executing generator. Below programs illustrate the ReflectionGenerator::getTrace() function in PHP: Program_1:
php
<?php
class Company
{
public function GFG()
{
yield 0;
}
}
$A = ( new Company)->GFG();
$B = new ReflectionGenerator( $A );
$C = $B ->getTrace();
var_dump( $C );
?>
|
Program_2:
php
<?php
function Department1() {
yield 1;
}
function Department2()
{
yield from Department1();
}
function Department3()
{
yield from Department2();
}
$A = Department3();
$A ->valid();
$A = new ReflectionGenerator( $A );
$B = $A ->getTrace();
var_dump( $B );
?>
|
Output:
array(2) {
[0]=>
array(4) {
["file"]=>
string(42) "/home/5ae62f6794b195f5dfeff893639bead9.php"
["line"]=>
int(10)
["function"]=>
string(11) "Department1"
["args"]=>
array(0) {
}
}
[1]=>
array(4) {
["file"]=>
string(42) "/home/5ae62f6794b195f5dfeff893639bead9.php"
["line"]=>
int(15)
["function"]=>
string(11) "Department2"
["args"]=>
array(0) {
}
}
}
Reference: https://www.php.net/manual/en/reflectiongenerator.gettrace.php
Share your thoughts in the comments
Please Login to comment...