Reflection ReflectionClass::getReflectionConstants

(PHP 7 >= 7.1.0, PHP 8)

ReflectionClass::getReflectionConstants — 클래스 상수를 가져옵니다.


설명

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

반영된 상수를 검색합니다.


매개변수

filter
원하는 일정한 가시성을 필터링하기 위한 선택적 필터. ReflectionClassConstant 상수를 사용하여 구성되며 기본값은 모든 상수 가시성입니다.

반환 값

ReflectionClassConstant 객체의 배열입니다.


변경 로그

버전 설명
8.0.0 filter가 추가되었습니다.

Examples

예제 #1 기본 ReflectionClass::getReflectionConstants() 예제

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

기타