Reflection ReflectionProperty::getDocComment
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
ReflectionProperty::getDocComment — 속성 문서 주석을 가져옵니다.
설명
public ReflectionProperty::getDocComment(): string|false
속성에 대한 문서 주석을 가져옵니다.
매개변수
이 함수에는 매개변수가 없습니다.
반환 값
문서 주석이 있는 경우 그렇지 않으면 false
입니다.
Examples
예제 #1 ReflectionProperty::getDocComment() 예제
<?php
class Str
{
/**
* @var int The length of the string
*/
public $length = 5;
}
$prop = new ReflectionProperty('Str', 'length');
var_dump($prop->getDocComment());
?>
위의 예는 다음과 유사한 결과를 출력합니다.
string(53) "/** * @var int The length of the string */"
예제 #2 여러 속성 선언
여러 속성 선언 앞에 단일 문서 주석이 있는 경우 문서 주석은 첫 번째 속성만 참조합니다.
<?php
class Foo
{
/** @var string */
public $a, $b;
}
$class = new \ReflectionClass('Foo');
foreach ($class->getProperties() as $property) {
echo $property->getName() . ': ' . var_export($property->getDocComment(), true) . PHP_EOL;
}
?>
위의 예는 다음을 출력합니다.
a: '/** @var string */' b: false
기타
- ReflectionProperty::getModifiers() - 속성 수정자를 가져옵니다.
- ReflectionProperty::getName() - 속성 이름 가져오기
- ReflectionProperty::getValue() - Gets value