Call private methods and private properties from outside a class in PHP

前端 未结 8 1868
离开以前
离开以前 2020-12-15 18:21

I want to access private methods and variables from outside the classes in very rare specific cases.

I\'ve seen that this is not be possible although introspection

8条回答
  •  执念已碎
    2020-12-15 19:01

    I have these problems too sometimes, however I get around it through my coding standards. Private or protected functions are denoted with a prefix underscore ie

    private function _myPrivateMethod()
    

    Then i simply make the function public.

    public function _myPrivateMethod()
    

    So although the function is public the naming convention gives the notification that whilst public is is private and shouldn't really be used.

提交回复
热议问题