Re: Use of 'self' in static function in subclass

From: Date: Tue, 01 Jun 2004 19:13:54 +0000
Subject: Re: Use of 'self' in static function in subclass
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-10230@lists.php.net to get a copy of this message
On Tue, 2004-06-01 at 15:11, Bert Slagter wrote: > Hi All, > > I have a class and a subclass, both with a static method: [...] > Somehow this behaviour seems logical, on the other hand I don't think > it's desired. I think that 'self' should point to the current class, > even if the static method resides in a parent class. > > Is this 'self'-behaviour intended? Yes: self is bound at compiletime. It would need to be changed to evaluation at runtime und would be far more useful then. This has been reported a couple of times, in slight variations: http://zend.com/lists/engine2/200307/msg00033.html http://zend.com/lists/engine2/200307/msg00036.html http://zend.com/lists/engine2/200309/msg00024.html In one of these, Marcus suggested a new keyword "this" which would behave like a run-time self, e.g: class Test { public static function getInstance() { return new this(); } } class Foo extends Test { } var_dump(Foo::getInstance()); would output "object(foo)" instead of "object(test)". I wouldn't mind chaning self in the first place, though. - Timm

« previous php.internals (#10230) next »