我有一个实现几个抽象方法的类。当我扩展该类时,我收到以下致命错误消息:
Class CI_Controller_Rest contains 6 abstract methods and must therefore be declared abstract or implement the remaining methods
使用抽象方法的类:
class CI_Controller_Rest extends CI_Controller {
public function __construct() {
parent::__construct();
}
abstract public function index();
abstract public function get();
abstract public function head();
abstract public function post();
abstract public function put();
abstract public function delete();
}
我延伸CI_Controller_Rest
的课程:
class Welcome extends CI_Controller_Rest {
public function __construct()
{
parent::__construct();
}
public function index() {}
public function get() {}
public function head() {}
public function post() {}
public function put() {}
public function delete() {}
}
我应该做些什么呢?
答案 0 :(得分:22)
如果一个类有一个或多个抽象函数,it MUST be declared as an abstract class:
abstract class CI_Controller_Rest extends CI_Controller {
public function __construct() {
parent::__construct();
}
abstract public function index();
abstract public function get();
abstract public function head();
abstract public function post();
abstract public function put();
abstract public function delete();
}
答案 1 :(得分:0)
abstract class CI_Controller_Rest extends CI_Controller {
public function __construct() {
parent::__construct();
}
abstract public function index();
abstract public function get();
abstract public function head();
abstract public function post();
abstract public function put();
abstract public function delete();
}
答案 2 :(得分:0)
CI_Controller_Rest必须是抽象类,因为它包含抽象方法
//