Let’s have this class
class A {
protected static function ident() { return "I am A"; }
public static function say() { return "I say '".self::ident()."'!"; }
}
Then I need to extend class A and override the ident() like this
class B extends A {
protected static function ident() { return "I am B"; }
}
Now when B::say(); is called, the result is I say ‘I am A’. Is there any technique how to force it to produce I say ‘I am B’ without overriding the say() method? (Please don’t ask me why to do this, just trust me it is reasonable in my project)
I believe it is possible via abstract class or interface, but I can not figure out how. If it is impossible in PHP, is there any language (except Haskell) which implements this feature?
Since PHP 5.3 late static bindings are available. You shouled take a look at that.
http://php.net/manual/en/language.oop5.late-static-bindings.php