当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP ReflectionGenerator getExecutingFile()用法及代码示例


ReflectionGenerator::getExecutingFile()函数是PHP中的内置函数,用于返回指定的当前正在执行的生成器的完整路径和文件名。

用法:

string ReflectionGenerator::getExecutingFile( void )

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


返回值:此函数返回指定的当前正在执行的生成器的完整路径和文件名。

以下示例程序旨在说明PHP中的ReflectionGenerator::getExecutingFile()函数:

示例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 getExecutingFile() function 
$C = $B->getExecutingFile(); 
  
// Getting the full path and file name 
// of the currently 
// executing generator 'A' 
echo $C; 
?>

输出:

/home/3ce672c0079010c54e57cdedc34d0188.php

示例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 getExecutingFile() function 
// and getting the full path and file  
// name of the currently 
// executing generators 
echo "File: {$D->getExecutingFile()}"; 
echo "\n"; 
echo "File: {$E->getExecutingFile()}"; 
echo "\n"; 
echo "File: {$F->getExecutingFile()}"; 
?>

输出:

File: /home/f12a7584188452b12381b38e3985f9d3.php
File: /home/f12a7584188452b12381b38e3985f9d3.php
File: /home/f12a7584188452b12381b38e3985f9d3.php

参考: https://www.php.net/manual/en/reflectiongenerator.getexecutingfile.php



相关用法


注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 PHP | ReflectionGenerator getExecutingFile() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。