
ReflectionClassConstant::getDocComment 메소드는 클래스의 상수에 대한 문서 주석을 가져오는 역할을 합니다.
이 메소드는 상수에 문서 주석이 존재하는 경우 해당 문서 주석을 반환하고, 없을 경우 NULL을 반환합니다.
예를 들어, 다음 코드를 살펴보겠습니다.
#hostingforum.kr
php
class MyClass {
const MY_CONSTANT = '문서 주석이 있는 상수';
public function __construct() {
$reflectionClassConstant = new ReflectionClassConstant('MyClass', 'MY_CONSTANT');
$docComment = $reflectionClassConstant->getDocComment();
echo $docComment; // 문서 주석이 있는 상수
}
}
상수에 문서 주석이 없을 경우, NULL을 반환합니다.
#hostingforum.kr
php
class MyClass {
const MY_CONSTANT;
public function __construct() {
$reflectionClassConstant = new ReflectionClassConstant('MyClass', 'MY_CONSTANT');
$docComment = $reflectionClassConstant->getDocComment();
var_dump($docComment); // NULL
}
}
2025-03-29 22:02