douwan4993 2012-04-26 04:13
浏览 33
已采纳

PHP代码对我不了解。 请解释[关闭]

$arr = NSZone::find_all(array('per_page'=>20, 'page'=>1));  

return result is

 [0] => NSZone Object
        (
            [xml_skip_attribs:protected] => Array
                (
                    [0] => id
                )

            [vals:protected] => Array
                (
                    [total_count] => 3
                )
        )

he is accessing

arr[0]['vals:protected']['total_count'] in this way arr[0]->total_count()  

That's mean total_count() is a function whereas according to array structure its look like array index. Please Explain me this code, how it work? What is [vals:protected] and can it be public, private etc as well, Any more explanation you know please?

  • 写回答

2条回答 默认 最新

  • doumao1047 2012-04-26 04:24
    关注

    That is not an array but a print_r($arr) of the NSZone Object, if your not in the class meaning your accessing it in the same scope as your using print_r($arr) and the property's are set to private/protected then you cannot access the values within the object if your outside of it, you would need to add a getter of sort, or change it to public.

    If the class using a __get() magic method you maybe could access it like: $arr->total_count;

    or you could add a method to get it, and access it like:$arr->getCount();

    public function getCount(){
      return $this->vals->total_count;
    }
    

    But without seeing the class, its hard to tell, so I could be completely out.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用