how to get if array key is protected?

断了今生、忘了曾经 提交于 2019-12-04 05:30:57

问题


i have this type of array:-
i want to get array elemtn.

context_course Object
 (
                     [_id:protected] => 15
                     [_contextlevel:protected] => 50
                     [_instanceid:protected] => 2 
                     [_path:protected] => /1/3/15 [_depth:protected] => 3 
)

the problem is [_id:protected]
i want to there value 15
how can i get if element is protected.
thanks.


回答1:


If a property is protected, it means the developer of the class doesn't want you to be able to freely directly access or modify its value from the public context.

If you analyze the class definition for this object, you will most likely find a method that will give you access to the value, for example it could be:

$obj->getId();

More info: Property Visibility




回答2:


This is not an array, it is an object.

You will need to implement a public accessor, also known as a getter to access the object property.

class context_course 
{
  public function getId()
  {
    return $this->_id;
  }
}


来源:https://stackoverflow.com/questions/17082204/how-to-get-if-array-key-is-protected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!