ReflectionProperty::getDocComment
(PHP 5 >= 5.1.0, PHP 7)
ReflectionProperty::getDocComment — プロパティのドキュメントコメントを取得する
説明
public ReflectionProperty::getDocComment ( ) : string
プロパティのドキュメントコメントを取得します。
パラメータ
この関数にはパラメータはありません。
返り値
プロパティのドキュメントコメントを返します。
例
例1 ReflectionProperty::getDocComment() の例
<?phpclass 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 複数のプロパティを宣言している場合
複数のプロパティの宣言が、 単一のドキュメントコメントの後に行われている場合、 ドキュメントコメントは最初のプロパティのみを参照します。
<?phpclass 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() - 値を取得する