当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。