略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ReflectionClass::getReflectionConstants

2024-11-15

ReflectionClass::getReflectionConstants

(PHP 7 >= 7.1.0, PHP 8)

ReflectionClass::getReflectionConstantsGets class constants

说明

public ReflectionClass::getReflectionConstants(?int $filter = null): array

Retrieves reflected constants.

参数

filter

The optional filter, for filtering desired constant visibilities. It's configured using the ReflectionClassConstant constants, and defaults to all constant visibilities.

返回值

An array of ReflectionClassConstant objects.

更新日志

版本 说明
8.0.0 filter has been added.

范例

示例 #1 Basic ReflectionClass::getReflectionConstants() example

<?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);

?>

以上例程的输出类似于:

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"
  }
}

参见

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/reflectionclass.getreflectionconstants.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3