2011-11-07 70 views
0

所以在我的代碼有:問題與PHP數組和500錯誤

var_dump($poll); 

它打印:

object(stdClass)#2 (9) { 
    ["parent"]=> object(stdClass)#3 (3) { 
     ["className"]=> string(5) "Venue" 
     ["__type"]=> string(7) "Pointer" 
     ["objectId"]=> string(10) "HRSCYpe2FK" 
    } 
    ["no"]=> int(0) 
    ["updatedAt"]=> string(24) "2011-11-06T23:37:17.917Z" 
    ["creator"]=> object(stdClass)#4 (3) { 
     ["className"]=> string(5) "_User" 
     ["__type"]=> string(7) "Pointer" 
     ["objectId"]=> string(10) "96K81tdpM4" 
    } 
    ["createdAt"]=> string(24) "2011-11-06T23:37:14.591Z" 
    ["yes"]=> int(1) 
    ["objectId"]=> string(10) "U8ly32582W" 
    ["question"]=> string(20) "Negozio conveniente?" 
    ["reports"]=> object(stdClass)#5 (0) { } 
} 

,然後我想做的事:

var_dump($poll["parent"]["objectId"]); 

但隨後它給我一個500內部服務器錯誤。任何想法爲什麼這是?

UPDATE: 從錯誤中拉日誌,它說:

PHP Fatal error: Cannot use object of type stdClass as array

回答

3

看起來你$poll變量是stdclass在這種情況下,你會獲得像這樣

var_dump($poll->parent->objectId) 

屬性至於你的500狀態,猜測我會說PHP被配置爲觸發這個錯誤。

0

這是因爲你正在綁定一個對象而不是數組的var_dump。

$ poll-> parent-> objectId;

object :: object :: property