I had never thought too much about how php handles static methods and properties in classes until I started fiddling with my activerecord again today. I had run into problems before but after less than satisfactory responses from the people writing people (you aren't doing OO right, no other language does this, it has to be done at compile time, blah blah blah) I simply did workarounds where static methods/properties and inheritence should have been used. Bottom line? Php does NOT support inheritence with statics. You can't even fake it.
I'm online, I read alot, I'd run across all this zend framework hype and seem some of the code you could supposedly use. I have a version of activerecord that required an instance to call find methods - worked really nifty, returned a collection class that lazy created activerecord instances as they were accessed - really rather cool, anyway. So I decided maybe there was some way to get static calls to those find methods working, after all, zend managed it, right???
To make a long story short...
/start rant/ I couldn't get it to work, not with reflection, not with debug_backtrace tricks...it just refused to cooperate. After reading around the internet about the "zend framework" version of active record and seeing the "psuedocode" it made me irritated - there was no way their code was possible in php currently. I find it annoying that zend is pushing this whole framework thing and showing examples that aren't possible. Bottom line? I was right, the code from the webcast was vaporware *proceeds to laugh in very evil voice* - and if they were just showing what they "hoped the final syntax would be" then they damn well should have SAID SO /end rant/
So in the end bitched to my brother about it ( and he blogged about it )
Anyway, I reverted back to my original work (look at the comments in the post linked above, zend has done the same) - forcing an instance for find calls instead of allowing static calls - a nice side effect is this makes sure my constructor gets called every time (sets up the db stuff really niftily)
I hope they do eventually fix the problem. Right now the static stuff is basically useless for any kind of extended class. I find it rather annoying that they haven't fixed the problem BEFORE now - after all, the bugs (marked bogus or wont fix because obviously the zend guys weren't using php5 at that point if they didn't see the problem until zend framework came along) the bugs/requests have been around for a LONG TIME
Here's a list :)
get_class() with no argument, always return the original classname
Special keyword 'self' inherited in child classes
Inheritance of private static variables fails (related to self:: )
Changing a static variables in a class changes it across sub/super classes
Inheritance of static functions
get_class(self) for static methods
Now most of these are marked bogus (erroneously, they should have been wont fix) or wontfix which is just annoying. And I've noticed that any comments in the documentation for statics that link to these bugs disappear... can we just get a way to get the calling class in a static method? is that so dang hard? And I'm one who would love __call to work on statics and have static constructors...that would really make my day...
I believe the original place I ran into this problem was with a singleton class that any class you wanted to keep as a singleton would extend - you'd have a factory method that would fetch the stored instance for each one simply by extending it - but since you couldn't stick all the code into one spot because you couldn't figure out what child was calling the parent static - you were screwed or had to do too much cut and paste... so I had to move to a factory class to keep track of all the instances (thus tying the framework portion of my stuff together more tightly, something I'd wanted to AVOID doing)
As to actually fixing the problem? We'll see how all this pans out...after all, it's only been what, January 2004 or so? Two years isn't too long to ask to have to stop doing workarounds and have static methods actually use inheritence...