Blog

Read our ramblings

Completing so many design, development and app projects gives us a unique insight you won't find anywhere else

Dougall Winship

·4 min read
Software

Breaking inheritance in Object Orientated PHP

** Warning : do not do this! **

Using a combination of PHP's magic methods and reflection it's possible to nearly completely sidestep PHP's OO inheritance visibility. Obviously this isn't a good thing under very nearly all circumstances ... just because you can do something doesn't mean you should!

  

The technique is very simple ... you intercept calls made to private methods/attibutes using PHP's magic methods __get __set __call and __callStatic, find the private method or attribute in question and force it to be available via reflection's setAccessible(...) method.

  

Note that you'll probably want to turn on php display errors

...
Read more

We use cookies, review our privacy policy here.