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?