doufuxing8562 2012-06-23 11:20
浏览 43
已采纳

访问PHP对象数组

Need some quick advice I am trying to access a object array but I am struggling, please see the below array. It starts off an object I would normally user $result->_messages->token but it doesnt work I have trawled google and this site but cant access the token.

object(Zend_Auth_Result)#76 (3) {
["_code":protected] => int(1)
["_identity":protected] => string(9) "3232323233"
["_messages":protected] => array(2) {
    ["user"] => object(stdClass)#71 (13) {
      ["id"] => string(9) "232323332"
      ["name"] => string(14) "John Smith"
      ["first_name"] => string(5) "John"
      ["last_name"] => string(8) "Smith"
      ["link"] => string(41) "http://www.facebook.com/"
      ["username"] => string(17) "john.smith"
      ["location"] => object(stdClass)#68 (2) {
        ["id"] => string(0) ""
        ["name"] => NULL
      }     
      ["email"] => string(22) "john@doe.com"
      ["timezone"] => int(1)
      ["locale"] => string(5) "en_US"
      ["verified"] => bool(true)
      ["updated_time"] => string(24) "2012-06-21T13:57:12+0000" 
    }
    ["token"] => string(109) "AAAGIFdDivU4BAMoxyHT3bqY8eBGhnWo9YKM1szHZAnWgY10AIBgxz9LeNCeA2HV9Yhkp8uM5Aq0WR39ZBdcnOa4MxXVI22rnmFKNbYdQZDZD"
    }
}

Any advice any body?

Cheers

J

  • 写回答

2条回答 默认 最新

  • drahywu329376 2012-06-23 11:40
    关注

    From the ZF Reference Guide on Naming Conventions:

    For instance variables that are declared with the "private" or "protected" modifier, the first character of the variable name must be a single underscore. This is the only acceptable application of an underscore in a variable name. Member variables declared "public" should never start with an underscore.

    So you cannot access _messages directly from outside the Zend_Auth_Result instance, because it is protected. You have to use the getter for that property.

    See the API Docs for Zend_Auth_Result

    $messages = $zendAuthResult->getMessages();
    $token = $messages['token'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c