當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP Reflection getModifierNames()用法及代碼示例


Reflection::getModifierNames()函數是PHP中的內置函數,用於返回指定修飾符名稱的數組。

用法:

array Reflection::getModifierNames( int $modifiers )

參數:此函數接受單個參數$modifiers,它是修飾符的Bitfield。此處,位域是一種數據結構,由多個相鄰的計算機存儲位置組成。


返回值:此函數返回指定修飾符名稱的數組。

以下示例程序旨在說明PHP中的Reflection::getModifierNames()函數:
程序1:

<?php 
  
// Declaring a class Testing 
class Testing 
{  
      
    // Calling a function GeeksforGeeks() with 
    // two modifier named as public and static 
    public static function GeeksforGeeks() 
    { 
        return; 
    } 
} 
  
// ReflectionMethod is called on the class Testing and 
// their member as funtion GeeksforGeeks() 
$GeeksforGeeks = new ReflectionMethod('Testing', 'GeeksforGeeks'); 
  
// Calling the getModifierNames() function and printing 
// an array of modifier names 
echo implode(' ', Reflection::getModifierNames($GeeksforGeeks->getModifiers())); 
?>

輸出:

public static

程序2:

<?php 
  
// Declaring a class Testing 
class Testing 
{  
      
    // Calling a function GFG() with 
    // two modifier named as public and static 
    final public function GFG() 
    { 
        return; 
    } 
} 
  
// ReflectionMethod is called on the class Testing and 
// their member as funtion GFG() 
$GFG = new ReflectionMethod('Testing', 'GFG'); 
  
// Calling the getModifierNames() function and printing 
// an array of modifier names 
echo implode(' ', Reflection::getModifierNames($GFG->getModifiers())); 
?>

輸出:

final public

參考: https://www.php.net/manual/en/reflection.getmodifiernames.php



相關用法


注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 PHP | Reflection getModifierNames() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。