ReflectionProperty::getDocComment

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

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

説明

public 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

参考

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top