首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

ReflectionClass::getReflectionConstants

(PHP 7 >= 7.1.0)

ReflectionClass::getReflectionConstants - 获取类常量

描述

代码语言:javascript
复制
public array ReflectionClass::getReflectionConstants ( void )

检索反射的常量。

参数

该函数没有参数。

返回值

一个ReflectionClassConstant对象的数组。

示例

示例#1基本的ReflectionClass::getReflectionConstants()示例

代码语言:javascript
复制
<?php
class Foo {
    public    const FOO  = 1;
    protected const BAR  = 2;
    private   const BAZ  = 3;
}

$foo = new Foo();

$reflect = new ReflectionClass($foo);
$consts  = $reflect->getReflectionConstants();

foreach ($consts as $const) {
    print $const->getName() . "\n";
}

var_dump($consts);

?>

上面的例子会输出类似于:

代码语言:javascript
复制
FOO
BAR
BAZ
array(3) {
  [0]=>
  object(ReflectionClassConstant)#3 (2) {
    ["name"]=>
    string(3) "FOO"
    ["class"]=>
    string(3) "Foo"
  }
  [1]=>
  object(ReflectionClassConstant)#4 (2) {
    ["name"]=>
    string(3) "BAR"
    ["class"]=>
    string(3) "Foo"
  }
  [2]=>
  object(ReflectionClassConstant)#5 (2) {
    ["name"]=>
    string(3) "BAZ"
    ["class"]=>
    string(3) "Foo"
  }
}

另请参阅

  • ReflectionClass::getReflectionConstant() - 获取类常量的ReflectionClassConstant
  • ReflectionClassConstant

← ReflectionClass::getReflectionConstant

ReflectionClass::getShortName →

扫码关注腾讯云开发者

领取腾讯云代金券