Call a protected method from outside a class in PHP

Posted by Chad Johnson on Stack Overflow See other posts from Stack Overflow or by Chad Johnson
Published on 2009-06-11T17:33:54Z Indexed on 2010/03/30 14:23 UTC
Read the original article Hit count: 500

Filed under:
|

I have a very special case in which I need to call a protected method from outside a class. I am very conscious about what I do programmingwise, but I would not be entirely opposed to doing so in this one special case I have. In all other cases, I need to continue disallowing access to the internal method, and so I would like to keep the method protected.

What are some elegant ways to access a protected method outside of a class? So far, I've found this.

I suppose it may be possible create some kind of double-agent instance of the target class that would sneakily provide access to the internals...

© Stack Overflow or respective owner

Related posts about php

Related posts about access-modifiers