I'm working with Wordpress and need to instantiate a new class similar to this oversimplified example (for an add_action()
hook which receives some arguments):
class A {
public function __construct() {
}
public static function init() {
$instance = new self();
$instance->doStuff();
}
protected function doStuff() {
echo get_class($this);
}
}
class B extends A {
}
B::init(); //returns 'A'
How can I get self
in init()
to refer to extended classes when called from them? I'm aware of the late static bindings page in the PHP docs, but I'm not clear on how to apply it in the above context. Thanks!