
ReflectionProperty::getDocComment() 메소드는 프로퍼티에 대한 설명을 가져올 때, 프로퍼티가 private 또는 protected 인 경우 null을 반환합니다.
이유는 PHP에서 private 또는 protected 프로퍼티는 외부에서 직접 접근할 수 없기 때문입니다. ReflectionClass와 ReflectionProperty는 PHP의 내부 구조를 분석할 수 있지만, private 또는 protected 프로퍼티의 설명은 외부에서 접근할 수 없기 때문에 null을 반환합니다.
프로퍼티가 public 인 경우, 프로퍼티에 대한 설명을 가져올 수 있습니다.
예를 들어, 다음 코드를 실행했을 때, 프로퍼티에 대한 설명을 가져올 수 있습니다.
#hostingforum.kr
php
$reflectionClass = new ReflectionClass('클래스명');
$property = $reflectionClass->getProperty('프로퍼티명');
if ($property->isPublic()) {
$docComment = $property->getDocComment();
var_dump($docComment);
}
이 코드는 프로퍼티가 public 인 경우에만 프로퍼티에 대한 설명을 가져옵니다.
2025-06-22 01:52