PHP数组的问题和500错误

时间:2011-11-07 00:16:30

标签: php

所以在我的代码中我有:

 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内部服务器错误。知道为什么会这样吗?

更新 从错误日志中提取它说:

  

PHP致命错误:无法使用stdClass类型的对象作为数组

2 个答案:

答案 0 :(得分:3)

您的$poll变量看起来像stdclass,在这种情况下,您可以访问这样的属性

var_dump($poll->parent->objectId)

至于您的500状态,我猜测PHP配置为触发此错误。

答案 1 :(得分:0)

这是因为你想要对一个对象而不是一个数组做一个var_dump。

$ poll->父 - >的ObjectID;

object :: object :: property

相关问题