ReflectionGenerator::getTrace()函數是PHP中的內置函數,用於返回指定的當前正在執行的生成器的跟蹤。
用法:
array ReflectionGenerator::getTrace ( void )
參數:該函數不接受任何參數。
返回值:此函數返回指定的當前正在執行的生成器的跟蹤。
以下示例程序旨在說明PHP中的ReflectionGenerator::getTrace()函數:
程序_1:
<?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 getTrace() function
$C = $B->getTrace();
// Getting the trace of the specified
// executing generator 'A'
var_dump($C);
?>輸出:
array(0) {
}
程序_2:
<?php
// Initializing a user-defined function
function Department1() {
yield 1;
}
function Department2()
{
yield from Department1();
}
function Department3()
{
yield from Department2();
}
// Creating a generator
$A = Department3();
// Starting the generator
$A->valid();
// Using ReflectionGenerator() over the
// above generator 'A'
$A = new ReflectionGenerator($A);
// Calling the getTrace() function
$B = $A->getTrace();
// Getting the the trace of the
// executing generator 'A'
var_dump($B);
?>輸出:
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) {
}
}
}
參考: https://www.php.net/manual/en/reflectiongenerator.gettrace.php
相關用法
- PHP ReflectionGenerator getExecutingFile()用法及代碼示例
- PHP ReflectionGenerator getExecutingLine()用法及代碼示例
- PHP ReflectionGenerator getExecutingGenerator()用法及代碼示例
- PHP ReflectionGenerator getThis()用法及代碼示例
- PHP ReflectionGenerator getFunction()用法及代碼示例
- d3.js d3.rgb()用法及代碼示例
- p5.js int()用法及代碼示例
- PHP dir()用法及代碼示例
- PHP pi( )用法及代碼示例
- CSS rgb()用法及代碼示例
- d3.js d3.map.get()用法及代碼示例
- CSS url()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 PHP | ReflectionGenerator getTrace() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
