當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP ReflectionProperty getDocComment()用法及代碼示例


ReflectionProperty::getDocComment()函數是PHP中的內置函數,用於返回指定屬性的文檔注釋。

用法:

string ReflectionProperty::getDocComment ( void )

參數:該函數不接受任何參數。


返回值:此函數返回指定屬性的文檔注釋。

以下示例程序旨在說明PHP中的ReflectionProperty::getDocComment()函數:
程序1:

<?php 
  
// Initializing a user-defined class Company 
class Company 
{ 
    /** 
     * @Below is the Size of GeeksforGeeks String 
     */
    public $SizeOfGeeksforGeeks = 13; 
  
    /** 
     * @Below is the Size of GFG String 
     */
    public $SizeOfGFG = 3; 
} 
  
// Using ReflectionProperty  
$A = new ReflectionProperty('Company', 'SizeOfGeeksforGeeks'); 
$B = new ReflectionProperty('Company', 'SizeOfGFG'); 
  
// Calling the getDocComment() function 
$C = $A->getDocComment(); 
$D = $B->getDocComment(); 
  
// Getting the doc comment of the specified property 
var_dump($C); 
var_dump($D); 
?>

輸出:

string(63) "/**
     * @Below is the Size of GeeksforGeeks String
     */"
string(53) "/**
     * @Below is the Size of GFG String
     */"

程序2:

<?php 
  
// Initializing some user-defined classes 
class Department1 
{ 
    /** 
     * @Below is the Size of HR String 
     */
    public $SizeOfHR = 2; 
} 
class Department2 
{ 
    /** 
     * @Below is the Size of Coding String 
     */
    public $SizeOfCoding = 6; 
} 
class Department3 
{ 
    /** 
     * @Below is the Size of Marketing String 
     */
    public $SizeOfMarketing = 9; 
} 
  
// Using ReflectionProperty over above classes 
$A = new ReflectionProperty('Department1', 'SizeOfHR'); 
$B = new ReflectionProperty('Department2', 'SizeOfCoding'); 
$C = new ReflectionProperty('Department3', 'SizeOfMarketing'); 
  
// Calling the getDocComment() function 
$D = $A->getDocComment(); 
$E = $B->getDocComment(); 
$F = $C->getDocComment(); 
  
// Getting the doc comments of the specified properties 
var_dump($D); 
var_dump($E); 
var_dump($F); 
?>

輸出:

string(52) "/**
     * @Below is the Size of HR String
     */"
string(56) "/**
     * @Below is the Size of Coding String
     */"
string(59) "/**
     * @Below is the Size of Marketing String
     */"

參考: https://www.php.net/manual/en/reflectionproperty.getdoccomment.php



相關用法


注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 PHP | ReflectionProperty getDocComment() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。