
ReflectionClassConstant::getDocComment 메서드는 ReflectionClass 인스턴스를 통해 상수 멤버 변수의 문서 주석을 얻을 수 있습니다.
예를 들어, 다음 코드를 통해 ReflectionClass 인스턴스를 생성하고 getDocComment 메서드를 사용하여 상수 멤버 변수의 문서 주석을 얻을 수 있습니다.
#hostingforum.kr
php
class MyClass {
const MY_CONSTANT = '문서 주석';
}
$reflectionClass = new ReflectionClass('MyClass');
$constant = $reflectionClass->getConstant('MY_CONSTANT');
$docComment = $reflectionClass->getConstant('MY_CONSTANT')->getDocComment();
echo $docComment;
이 코드는 '문서 주석'을 출력합니다.
또한, ReflectionClass 인스턴스를 생성한 후, getConstants 메서드를 사용하여 모든 상수 멤버 변수의 문서 주석을 얻을 수 있습니다.
#hostingforum.kr
php
class MyClass {
const MY_CONSTANT = '문서 주석';
const MY_CONSTANT2 = '문서 주석2';
}
$reflectionClass = new ReflectionClass('MyClass');
$constants = $reflectionClass->getConstants();
foreach ($constants as $constantName => $constantValue) {
$docComment = $reflectionClass->getConstant($constantName)->getDocComment();
echo "$constantName: $docCommentn";
}
이 코드는 모든 상수 멤버 변수의 문서 주석을 출력합니다.
이러한 예제를 통해 ReflectionClassConstant::getDocComment 메서드를 사용하여 상수 멤버 변수의 문서 주석을 얻을 수 있는 방법을 이해할 수 있습니다.
2025-06-10 22:31