开发者

PHP print_r private object

I have an object that has private keys like this _errors:private. I am trying to prin开发者_StackOverflow社区t_r farther down the multidimensional array (to get specific error codes). But when i try the print_r comes up empty. How do I get thous objects?


If it is private it means that it cannot be accesed from outside the class. You could writte a "getter", wich is a function that will return that value. You can think that as a bank vault and a teller. You cannot get your money from the vault yourself, you have to ask the teller (in programming, the getter) to go to te vault and get if to you.

private $secret_var;

public function secret_var_getter(){
   return $secret_var;
}

in this example, trying to do $object->secret_var will throw and error as it is a private property, but calling $object->secret_var_getter(); will get you the private var.


Make 'em public, write a getter, or use get_object_vars.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜