ReflectionProperty::getDocComment

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

ReflectionProperty::getDocCommentプロパティのドキュメントコメントを取得する

説明

publicReflectionProperty::getDocComment(): string|false

プロパティのドキュメントコメントを取得します。

パラメータ

この関数にはパラメータはありません。

戻り値

プロパティのドキュメントコメントを返します。 ドキュメントコメントが存在しない場合は、false を返します。

例1 ReflectionProperty::getDocComment() の例

<?php
class Str
{

public $length = 5;
}

$prop = new ReflectionProperty('Str', 'length');

var_dump($prop->getDocComment());

?>

上の例の出力は、 たとえば以下のようになります。

string(53) ""

例2 複数のプロパティを宣言している場合

複数のプロパティの宣言が、 単一のドキュメントコメントの後に行われている場合、 ドキュメントコメントは最初のプロパティのみを参照します。

<?php
class Foo
{

public $a, $b;
}
$class = new \ReflectionClass('Foo');
foreach (
$class->getProperties() as $property) {
echo
$property->getName() . ': ' . var_export($property->getDocComment(), true) . PHP_EOL;
}
?>

上の例の出力は以下となります。

a: '' b: false

参考

To Top