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


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。