I have an abstract class that has a method which uses a static function. This static function is defined in sub-classes and is different for each sub-class. Which sub-class will be used to create object is determined in the script. See super simplified code below:
abstract class fooClass implements iFooClass {
function getBar(){
$bar = self::getSomething();
return $bar;
}
}
interface iFooClass{
static function getSomething();
}
class fooSubClass_A extends fooClass {
static function getSomething() {
//do something;
//return something;
}
}
class fooSubClass_B extends fooClass {
static function getSomething() {
//do something else;
//return something else;
}
}
$foo = New fooSubClass_A;
$bar = $foo->getBar();
This code gives me this error:
Fatal error: Cannot call abstract method iFooClass::getSomething() in C:\wamp\www\Classes\fooClass.php on line 12
I thought since the sub-classes have access to super-classes method getBar it would be called from the sub-class and thus have access to its static function. Apparently not. Is there a way to redo this to make it work?