Php/docs/reflectionclass.getreflectionconstants
来自菜鸟教程
ReflectionClass::getReflectionConstants
(PHP 7 >= 7.1.0)
ReflectionClass::getReflectionConstants — Gets class constants
说明
public ReflectionClass::getReflectionConstants ( ) : array
Retrieves reflected constants.
参数
此函数没有参数。
范例
Example #1 Basic ReflectionClass::getReflectionConstants() example
<?phpclass 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);?>
以上例程的输出类似于:
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() - Gets a ReflectionClassConstant for a class's constant
- ReflectionClassConstant