我想做这样的事情:
abstract class Foo
{
public function __construct()
{
echo 'This is the parent constructor';
}
abstract function __construct();
}
class Bar extends Foo
{
// constructor is required as this class extends Foo
public function __construct()
{
//call parent::__construct() if necessary
echo 'This is the child constructor';
}
}
但是这样做时我遇到了一个致命错误:
Fatal error: Cannot redeclare Foo::__construct() in Foo.php on line 8
有没有另一种方法来确保子类有一个构造函数?