In PHP how can I access a “:private” array in an object?

后端 未结 3 1050
你的背包
你的背包 2020-12-10 13:43

Up until around 3.3beta1 items in the WP_Admin_Bar Object could be accessed using this type of syntax, for example to change the CSS class of one of the existin

3条回答
  •  北海茫月
    2020-12-10 14:01

    If I understand correctly your question, you're asking if you can access an object's private variables, but I guess you know you can't unless there's a method for it in the class, so this may be a trivial non-useful answer, but just in case:

    Look at the class' code. Does it have any method to retrieve those variables, like get_nodes(),get_root(), etc? If not you have 3 alternatives: recode the class set the vars public, recode the class and add the methods, or recode the class and set the variables protected, then create a new class extending the parent one with those methods (I recomend this one, since it has less impact on the parent class).

    Anyway if you can't recode the class and it has no get methods you won't be able to access those private variables.

提交回复
热议问题