PHP 8.1.28 Released!

ReflectionProperty::getDocComment

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

ReflectionProperty::getDocCommentÖzellik açıklamalarını döndürür

Açıklama

public ReflectionProperty::getDocComment(): string|false

Özellik ile ilgili açıklamaları döndürür.

Bağımsız Değişkenler

Bu işlevin bağımsız değişkeni yoktur.

Dönen Değerler

Varsa açıklamalar, yoksa false.

Örnekler

Örnek 1 - ReflectionProperty::getDocComment() örneği

<?php
class Str
{
/**
* @var int Dizge uzunluğu
*/
public $length = 5;
}

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

var_dump($prop->getDocComment());

?>

Yukarıdaki örnek şuna benzer bir çıktı üretir:

string(44) "/**
     * @var int  Dizge uzunluğu
     */"

Örnek 2 - Çoklu özellik bildirimi

Aynı belgelendirme açıklaması birden fazla özellik hakkında ise açıklama sadece ilk özellik için döner.

<?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;
}
?>

Yukarıdaki örneğin çıktısı:

a: '/** @var string */'
b: false

Ayrıca Bakınız

add a note

User Contributed Notes 1 note

up
1
Jim
1 year ago
Unfortunately, inherited doc comments are not supported.

<?php

class A {
/**
* @var string
*/
public string $prop = 'A';
}

class
B extends A {
public
string $prop = 'B';
}

$prop = new ReflectionProperty('B', 'prop');
var_dump($prop->getDocComment());

?>

results in FALSE
To Top