2013-02-07 90 views
0

我一直在這裏拉我的頭髮,包括在這裏回顧問題(比如這個例子:Read var_dump data with PHP),但我只是沒有得到它。PHP - 如何從一個對象中檢索一個值

我試圖檢索以下值:

COM_USERS_REGISTRATION_SAVE_FAILED 

,並存儲爲一個變量。這裏是絕對的爛攤子(我不知道),我試圖從檢索它(這是文本的最後一行):

object(UsersModelRegistration)#98 (9) 
    { ["data:protected"]=> object(stdClass)#106 (1) { 
     ["groups"]=> array(1) { 
      [0]=> string(1) "2" } }   
    ["_forms:protected"]=> array(0) { } 
    ["__state_set:protected"]=> NULL 
    ["_db:protected"]=> object(JDatabaseMySQL)#15 (19) { 
     ["name"]=> string(5) "mysql" 
     ["nameQuote:protected"]=> string(1) "`" 
     ["nullDate:protected"]=> string(19) "0000-00-00 00:00:00" 
     ["dbMinimum:protected"]=> string(5) "5.0.4" 
     ["_database:private"]=> string(15) "table_joomla" 
     ["connection:protected"]=> resource(29) of type (mysql link) 
     ["count:protected"]=> int(0) 
     ["cursor:protected"]=> resource(83) of type (Unknown) 
     ["debug:protected"]=> bool(false) 
     ["limit:protected"]=> int(0) 
     ["log:protected"]=> array(0) { } 
     ["offset:protected"]=> int(0) 
     ["sql:protected"]=> object(JDatabaseQueryMySQL)#126 (18) { 
      ["db:protected"]=> *RECURSION* 
      ["type:protected"]=> string(6) "select" 
      ["element:protected"]=> NULL 
      ["select:protected"]=> object(JDatabaseQueryElement)#127 (3) { 
       ["name:protected"]=> string(6) "SELECT" 
       ["elements:protected"]=> array(1) {[0]=> string(4) "`id`" } 
       ["glue:protected"]=> string(1) "," } 
      ["delete:protected"]=> NULL 
      ["update:protected"]=> NULL 
      ["insert:protected"]=> NULL 
      ["from:protected"]=> object(JDatabaseQueryElement)#128 (3) { 
       ["name:protected"]=> string(4) "FROM" 
       ["elements:protected"]=> array(1) { 
        [0]=> string(10) "`#__users`" } 
      ["glue:protected"]=> string(1) "," } 
      ["join:protected"]=> NULL 
      ["set:protected"]=> NULL 
      ["where:protected"]=> object(JDatabaseQueryElement)#129 (3) { 
       ["name:protected"]=> string(5) "WHERE" 
       ["elements:protected"]=> array(2) { 
        [0]=> string(31) "`username` = '[email protected]'" 
        [1]=> string(9) "`id` != 0" } 
      ["glue:protected"]=> string(5) " AND " } 
      ["group:protected"]=> NULL ["having:protected"]=> NULL 
      ["columns:protected"]=> NULL ["values:protected"]=> NULL 
      ["order:protected"]=> NULL ["union:protected"]=> NULL 
     ["autoIncrementField:protected"]=> NULL } 
     ["tablePrefix:protected"]=> string(6) "s7kou_" 
     ["utf:protected"]=> bool(true) 
     ["errorNum:protected"]=> int(0) 
     ["errorMsg:protected"]=> string(0) "" 
     ["hasQuoted:protected"]=> bool(false) 
    ["quoted:protected"]=> array(0) { } } 
    ["name:protected"]=> string(12) "registration" 
    ["option:protected"]=> string(9) "com_users" 
    ["state:protected"]=> object(JObject)#99 (1) { 
     ["_errors:protected"]=> array(0) { } } 
    ["event_clean_cache:protected"]=> string(19) "onContentCleanCache" 
    ["_errors:protected"]=> array(1) { 
     [0]=> string(34) "COM_USERS_REGISTRATION_SAVE_FAILED" } } 
+1

http://php.net/manual/en/language.oop5.visibility.php可能是相關的。 – Amber

回答

0

對象的所有屬性的保護,訪問你應該如何實現「干將」的UsersModelRegistration類/或延長UsersModelRegistration和實施干將

/** 
* @returns array 
*/ 
public function getErrors(){ 

return $this->_errors; 
} 
0

看一看類的來源,很可能是返回該值的方法。有解決方案來訪問受保護的屬性(Reflections或將對象轉換爲數組)我不會推薦這些,因爲它們完全破壞封裝的OOP原理。該屬性爲protected由於某種原因,您應該通過UserModelRegistration的公共接口訪問它。