PHP5, you king of bastards (setting an instance member inside a static class call)
2009 July 8
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() {
Inner_Static::burrito();
}
}
$my_guy = new Outer_Instance();
$my_guy->taco();
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?