
ReflectionExtension::getConstants 메서드는 단일 클래스의 상수 값을 반환합니다. 하지만, ReflectionClass를 사용하여 여러 클래스의 상수 값을 가져올 수 있습니다.
예를 들어, 다음과 같이 여러 클래스의 상수 값을 가져올 수 있습니다.
#hostingforum.kr
php
$reflectionClass1 = new ReflectionClass('클래스1');
$reflectionClass2 = new ReflectionClass('클래스2');
$constants1 = $reflectionClass1->getConstants();
$constants2 = $reflectionClass2->getConstants();
print_r($constants1);
print_r($constants2);
또한, ReflectionClass를 사용하여 여러 클래스의 상수 값을 한 번에 가져올 수도 있습니다.
#hostingforum.kr
php
$reflectionClasses = array(new ReflectionClass('클래스1'), new ReflectionClass('클래스2'));
$constants = array();
foreach ($reflectionClasses as $reflectionClass) {
$constants = array_merge($constants, $reflectionClass->getConstants());
}
print_r($constants);
이러한 방법으로 여러 클래스의 상수 값을 가져올 수 있습니다.
2025-05-21 02:38