
ReflectionClass::getConstants 메소드는 클래스의 상수 이름과 함께 상수 값을 모두 리턴합니다.
예를 들어, 다음 코드를 살펴보겠습니다.
#hostingforum.kr
php
class MyClass {
const MY_CONSTANT = 'Hello, World!';
}
$reflectionClass = new ReflectionClass('MyClass');
$constants = $reflectionClass->getConstants();
print_r($constants);
이 코드를 실행하면 다음과 같은 결과가 출력됩니다.
#hostingforum.kr
php
Array
(
[MY_CONSTANT] => Hello, World!
)
따라서, ReflectionClass::getConstants 메소드는 클래스의 상수 이름과 함께 상수 값을 모두 리턴합니다.
이 메소드를 사용하여 클래스의 상수 이름과 함께 상수 값을 가져올 수 있습니다.
2025-05-27 16:52