
ReflectionClass::getConstant 메소드는 클래스의 상수 값을 가져올 때, 상수 이름이 정확하게 맞아야 합니다.
상수 이름은 대소문자를 구분합니다. 예를 들어, 'MY_CONSTANT'과 'my_constant'은 다른 상수입니다.
상수 이름을 정확하게 입력하지 않으면, ReflectionClass::getConstant 메소드는 null을 반환합니다.
따라서, 상수 이름을 정확하게 입력하거나, 상수 이름을 대소문자를 구분하지 않는 대체 방법을 사용해야 합니다.
예를 들어, 상수 이름을 대문자로 입력하거나, 상수 이름을 대소문자를 구분하지 않는 대체 방법을 사용할 수 있습니다.
#hostingforum.kr
php
$reflectionClass = new ReflectionClass('MyClass');
$constantValue = $reflectionClass->getConstant('MY_CONSTANT');
또는
#hostingforum.kr
php
$reflectionClass = new ReflectionClass('MyClass');
$constantValue = $reflectionClass->getConstant('my_constant');
또는
#hostingforum.kr
php
$reflectionClass = new ReflectionClass('MyClass');
$constantValue = $reflectionClass->getConstants();
$constantValue = $constantValue['MY_CONSTANT'];
이러한 방법을 사용하여, ReflectionClass::getConstant 메소드를 사용하여 클래스의 상수 값을 가져올 수 있습니다.
2025-06-29 18:00