php – 错误:类必须声明为抽象或实现其余的方法

前端之家收集整理的这篇文章主要介绍了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() {}
}

我该怎么办?

如果一个类有一个或多个抽象函数,那么 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();
}

猜你在找的PHP相关文章