PHP5, you king of bastards (setting an instance member inside a static class call)

If I’m in an instanced class, and I call another class’s method statically inside of a method in the first class, and that static method should happen to (erroneously) have $this->whatever inside of it…

…it sets $whatever on my outer instanced class.

Here’s some illustrative code:

    class Inner_Static {
        function burrito() {
            $this->_member = ‘A keyboard. How quaint.’;

    class Outer_Instance {
        function taco() {

    $my_guy = new Outer_Instance();

    print ‘$my_guy->_member: ‘ . $my_guy->_member; 

This boggles my mind a bit. Tracking it down cost me a bit of time. Is there actually a sane use for this little tidbit, or am I justified in thinking that a good language would warn you that scope shenanigans are going on here?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.