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