« ReflectionProperty::getDefaultValue
ReflectionProperty::getHook »

ReflectionProperty::getDocComment

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

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

説明

public function ReflectionProperty::getDocComment(): string|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

参考

関連キーワード:
ReflectionProperty   プロパティ   ドキュメント   コメント   getDocComment   length   property   prop   複数   宣言   getName   getDefaultValue   getHook   dump   最初   ReflectionClass   foreach   getProperties   export   参考   getModifiers   修飾   getValue
関連する関数・ページ:
reflectionproperty.getname   reflectionproperty.isstatic   reflectionproperty.isprivate   reflectionproperty.isprotected   reflectionproperty.isreadonly   reflectionproperty.gettype