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


PHP ReflectionClass getReflectionConstants()用法及代碼示例


ReflectionClass::getReflectionConstants()函數是PHP中的一個內置函數,用於返回ReflectionClassConstant對象的數組。

用法:

array ReflectionClass::getReflectionConstants( void )

參數:該函數不接受任何參數。


返回值:此函數返回ReflectionClassConstant對象的數組。

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

<?php 
  
// Declaring a class named as Company 
class Company { 
      
    // Defining some constants 
    const First = "GeeksforGeeks"; 
    const Second = "GFG"; 
} 
  
// Using the ReflectionClass() function  
// over the Company class 
$A = new ReflectionClass('Company'); 
  
// Calling the getReflectionConstants() function 
$a = $A->getReflectionConstants(); 
  
// Getting an array of ReflectionClassConstant objects. 
print_r($a); 
?>

輸出:

Array
(
    [0] => ReflectionClassConstant Object
        (
            [name] => First
            [class] => Company
        )

    [1] => ReflectionClassConstant Object
        (
            [name] => Second
            [class] => Company
        )

)

示例2:

<?php 
  
// Using the ReflectionClass() function  
$A = new ReflectionClass('ReflectionClass'); 
  
// Calling the getReflectionConstants() function 
$a = $A->getReflectionConstants(); 
  
// Getting an array of ReflectionClassConstant objects. 
print_r($a); 
?>

輸出:

Array
(
    [0] => ReflectionClassConstant Object
        (
            [name] => IS_IMPLICIT_ABSTRACT
            [class] => ReflectionClass
        )

    [1] => ReflectionClassConstant Object
        (
            [name] => IS_EXPLICIT_ABSTRACT
            [class] => ReflectionClass
        )

    [2] => ReflectionClassConstant Object
        (
            [name] => IS_FINAL
            [class] => ReflectionClass
        )

)

參考: https://secure.php.net/manual/en/reflectionclass.getreflectionconstants.php



相關用法


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