
ReflectionClass::getDocComment 메소드는 클래스의 문서 주석을 반환하는 역할을 합니다. 이 메소드는 PHPDoc 형식의 문서 주석을 문자열로 반환합니다.
예를 들어, 다음 코드를 사용하여 클래스의 문서 주석을 확인할 수 있습니다.
#hostingforum.kr
php
class MyClass {
/
* MyClass 클래스 설명
*/
}
$reflectionClass = new ReflectionClass('MyClass');
$docComment = $reflectionClass->getDocComment();
echo $docComment;
이 코드를 실행하면 MyClass 클래스의 문서 주석이 출력됩니다.
이 메소드는 클래스의 문서 주석을 반환하기 때문에, 메소드나 프로퍼티의 문서 주석은 반환되지 않습니다.
만약 메소드나 프로퍼티의 문서 주석을 확인하려면, ReflectionMethod 또는 ReflectionProperty 클래스를 사용하여 문서 주석을 확인해야 합니다.
예를 들어, 다음 코드를 사용하여 메소드의 문서 주석을 확인할 수 있습니다.
#hostingforum.kr
php
class MyClass {
* MyClass 클래스 설명
*/
public function myMethod() {
/**
* myMethod 메소드 설명
*/
}
}
$reflectionClass = new ReflectionClass('MyClass');
$reflectionMethod = $reflectionClass->getMethod('myMethod');
$docComment = $reflectionMethod->getDocComment();
echo $docComment;
이 코드를 실행하면 myMethod 메소드의 문서 주석이 출력됩니다.
2025-04-18 08:13