プロパティのドキュメントコメントを取得する
プロパティのドキュメントコメントを取得します。
この関数にはパラメータはありません。
プロパティのドキュメントコメントを返します。 ドキュメントコメントが存在しない場合は、false を返します。
false
例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