Thursday, February 23. 2006Late Static Binding in PHPTrackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
A quick little update. My patch did its job in a not so optimal way in regards to the op_array structure. Long story short, I did it wrong once, did it a little bit better the second time, then dmitry rewrote the patch and did it in what I presume to be the right way.
So, long story short...a patch for late static binding in PHP exists and is out there. I am actually in the process of putting together some use cases to support it's inclusion. If you would like it to be included in the core of PHP I would highly recommend you make your opinions known.
I'd love to see late static binding (L.S.B.) in the engine. I ran into the limitation when building a generic 'RecordSet' type of class back in Nov'2003.
At that time I didn't know what the functionality I was looking was even called - to be totally honest I didn't even write the class initially, a friend of mine did it - since then my coding skills have become much better and I have been able to extend, rewrite and bugfix the codebase in question (constantly hoping for L.S.B.). The friend in question wrote the last incarnation of the interbase/firebird extension - anyone who uses it can atest to it's quality (the chap in question knows where his towel is, so to speak). My friend considered the lack of L.S.B an omission (at the least) - I still tend to agree! rgds,
Well I'm glad that someone is working on this.. I'm exactly in the middle of implementing a php ActiveRecord and I just ran into this compile-time binding brick wall. Any word on this patch's acceptance?
The patch's current incarnation is at a bit of a stand still right now. It is not an incredibly high priority for most of the core developers (save one MAYBE two) and I haven't had any time to work more on it. It definantly hasn't been forgotten and when I have more time I will probably bring it up again.
What is needed now is testing and use cases. So if you can contribute some real world use cases then feel free to post them here, or even email them to me directly: m () digitalsandwich ! com
Is there a typo in your example code? Foo::test() echos Foo::$foo, but that doesn't exist. Foo::$staticVar does, though.
Any updates on this patch? I've looked around the dev lists, and it looks like it might not even make it into PHP6...
As for a use case, I would like to extend a base database class and use an inherited loadById() method: class DataTable { protected $table; public function __construct() { $this->table = "default"; } public static function loadById($id) { $class = get_class(); // return new $class($id) can't work } } class BlogPost extends DataTable { protected $table = "blog"; } BlogPost::load();
To solve this problem when used in a normal method, i use this code:
class baseclass() { function getInfo() { // oops PHP bug-> self is determined at compile time, not at runtime. // even for derived classes, self is always basevideodriver // return self::getDriverInfo(); // also get_chass($this)::getDriverInfo() does not work.. 2nd PHP bug // so we need the help of evil eval() eval('$rv='.get_class($this).'::getDriverInfo();'); return $rv; } } class .. extends baseclass { static function getDriverInfo() { this is the one that needs to be called... } PHP is such a quircky language. Maybe we should ignore the current louzy php dev team and start a fork of php called "real-php" or so. |
Paying for the Site
QuicksearchCategoriesDaily Readsadam trachtenberg
Ben Ramsey Chris Shiflett Dynamically Typed (Harry Fuecks) george schlossnagle John Coggeshall John Lim Marco Tabini PHP Application Tools PHPCommunity.org Planet PHP Sebastian Bergmann Sklar The PHP WTF Tobias Schlitt Tom Sommer Wez Furlong |

