2013-05-12 77 views
2

評論,如果它是可能的(容易)在PHP工作再上一個類的屬性,例如評論:獲取有關我想知道屬性

/** 
* A test class 
* 
* @param int $TestId primary 
* @param string $Name 
* @param int $Age 
* @param char $Gender 
* @param date $DOB 
*/ 
class Test extends DataObject { 
    /** 
    * 
    * This is what I want 
    * 
    */ 
    public $TestId = 0; 
    public $Name = ""; 
    public $Age = 0; 
    public $Gender = "M"; 
    public $DOB = ""; 
} 

我想看看我是否能得到的評論TestId屬性容易嗎?

+0

爲什麼你的類在文檔塊中有'@ param'? – PeeHaa 2013-05-12 22:45:21

+0

在php中尋找反射屬性 – karthikr 2013-05-12 22:46:12

+0

我只是在玩弄它,看看我會得到什麼,但我並不關心DocComment。 – 2013-05-12 22:46:47

回答

1

ReflectionProperty::getDocComment

喜歡的東西:

$prop = new ReflectionProperty('Test', 'TestId'); 
print $prop->getDocComment(); 

有沒有內置DocComment解析器,但我寫了一個here如果你有興趣。

+0

感謝您的提議,但我已經使用過您的示例,並且正在做一些稍微不同的工作。 – 2013-05-15 13:27:15