错误:必须将类声明为abstract或实现其余方法

时间:2012-10-02 10:14:50

标签: php

我有一个实现几个抽象方法的类。当我扩展该类时,我收到以下致命错误消息:

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() {}
}  

我应该做些什么呢?

3 个答案:

答案 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必须是抽象类,因为它包含抽象方法

//