Get string within protected object

后端 未结 4 1001
庸人自扰
庸人自扰 2020-12-21 05:45

I am trying to get the the string \"this info\" inside this object lets call it $object, but data is protected, how can I access that pocket?

           


        
4条回答
  •  盖世英雄少女心
    2020-12-21 06:31

    If you - or the writer of the class - want other people to have access to a protected or private property, you need to provide that via a getter method in the class itself.

    So in the class:

    public function getData()
    {
      return $this->_data;
    }
    

    And in your program:

    $object->getData();
    

提交回复
热议问题