I need an inherited static function \"call\" to call another static function \"inner\" that has been overridden. I could do this with late static binding, but my host does
Unfortunately there is no nice way to do it (otherwise PHPers wouldn't cheer so much for that feature).
You have to pass class name. PHP < 5.3 also doesn't have nice syntax for static calls with dynamic class name which makes whole thing even uglier:
static function call($class)
{
return call_user_func(array($class,"inner"));
}
…
ClassA::call("ClassA");
ClassB::call("ClassB");
If you can change the code (and not use static
), then singletons make it more bearable. You can make helper function to ease the syntax:
X("ClassA")->call();
X("ClassB")->call();
The X function should look up, create and return instance of a class.