
ReflectionClass::getReflectionConstants 메서드는 호출한 클래스의 상수를 반환합니다. 상속 클래스의 상수는 포함되지 않습니다.
예를 들어, 다음 코드가 있다고 가정해 보겠습니다.
#hostingforum.kr
php
class ParentClass {
const PARENT_CONSTANT = '부모 클래스 상수';
public function __construct() {
// ...
}
}
class ChildClass extends ParentClass {
const CHILD_CONSTANT = '자식 클래스 상수';
}
$reflection = new ReflectionClass('ChildClass');
$constants = $reflection->getReflectionConstants();
print_r($constants);
이 경우, `$constants`에는 `CHILD_CONSTANT`만 포함됩니다.
상속 클래스의 상수도 포함하여 모든 상수를 반환하려면, `ReflectionClass`를 호출할 때 `ParentClass`를 호출하면 됩니다.
#hostingforum.kr
php
$reflection = new ReflectionClass('ParentClass');
$constants = $reflection->getReflectionConstants();
print_r($constants);
이 경우, `$constants`에는 `PARENT_CONSTANT`와 `CHILD_CONSTANT` 모두 포함됩니다.
2025-07-26 17:43