2012-02-07 32 views
-1

是否有從類中檢索所有屬性的函數/方法?如從下面我班上所有的屬性:OO PHP - 檢索類中的所有屬性

class plantOfTheMonth { 

    //Declare which centre(s) are being used 
    private $centre = ""; 

    //Declare the attributes of the current Plant Of The Month 
    private $name = ""; 
    private $latinName = ""; 
    private $image = ""; 
    private $imageAlt = ""; 
    private $imageLink = ""; 
    private $strapLine = ""; 
    private $description = ""; 
    private $color = ""; 
    private $centres = ""; 

    //Declare variables for error handling 
    private $issue = ""; 
    private $issueCode = ""; 

} 

回答

4
+1

'get_object_vars()'只會獲取可訪問的屬性,所以當從對象外部調用時,只會返回公共屬性。 – Mchl 2012-02-07 16:03:07

+0

感謝Crozin,我在上面的答案中使用了這個函數,就像在類裏面解決這個問題一樣:'public function test(){var_dump(get_object_vars($ this)); }' – 2012-02-07 16:11:26