What you're talking about is called Late Static Binding and it's available since PHP 5.3. All you need to do is use the word static
instead of self
:
class ClassA {
public static function test() { return static::getVar(); }
}
class ClassB extends ClassA {
public static function getVar() { return 'B'; }
}
echo ClassB::test(); // prints 'B'