ReflectionGenerator::getFunction()函數是PHP中的內置函數,用於返回指定生成器的函數名稱。
用法:
ReflectionFunctionAbstract ReflectionGenerator::getFunction ( void )
參數:該函數不接受任何參數。
返回值:此函數返回指定生成器的函數名稱。
以下示例程序旨在說明PHP中的ReflectionGenerator::getFunction()函數:
程序_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 getFunction() function 
$C = $B->getFunction(); 
  
// Getting the function name of the 
// specified generator 'A' 
var_dump($C); 
?>輸出:
object(ReflectionMethod)#4 (2) {
  ["name"]=>
  string(3) "GFG"
  ["class"]=>
  string(7) "Company"
}
程序_2:
<?php 
  
// Initializing a user-defined class Departments 
class Departments 
{ 
    public function Coding_Department() 
    { 
        yield 0; 
    } 
    public function HR_Department() 
    { 
        yield 1; 
    } 
    public function Marketing_Department() 
    { 
        yield 2; 
    } 
} 
  
// Creating some generators on the above 
// class Departments 
$A = (new Departments)->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 getFunction() function 
// and getting the function name of the 
// specified generators 
var_dump($D->getFunction()); 
echo "\n"; 
var_dump($E->getFunction()); 
echo "\n"; 
var_dump($F->getFunction()); 
?>輸出:
object(ReflectionMethod)#10 (2) {
  ["name"]=>
  string(17) "Coding_Department"
  ["class"]=>
  string(11) "Departments"
}
object(ReflectionMethod)#10 (2) {
  ["name"]=>
  string(13) "HR_Department"
  ["class"]=>
  string(11) "Departments"
}
object(ReflectionMethod)#10 (2) {
  ["name"]=>
  string(20) "Marketing_Department"
  ["class"]=>
  string(11) "Departments"
}
參考: https://www.php.net/manual/en/reflectiongenerator.getfunction.php
相關用法
- PHP ReflectionGenerator getTrace()用法及代碼示例
- PHP ReflectionGenerator getExecutingFile()用法及代碼示例
- PHP ReflectionGenerator getExecutingLine()用法及代碼示例
- PHP ReflectionGenerator getExecutingGenerator()用法及代碼示例
- PHP ReflectionGenerator getThis()用法及代碼示例
- d3.js d3.rgb()用法及代碼示例
- p5.js int()用法及代碼示例
- PHP dir()用法及代碼示例
- PHP pi( )用法及代碼示例
- CSS rgb()用法及代碼示例
- d3.js d3.map.get()用法及代碼示例
- CSS url()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 PHP | ReflectionGenerator getFunction() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
