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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12688436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:02:10  来源:igfitidea点击:

Error: Class must be declared abstract or implement the remaining methods

php

提问by Andrew

I have a class that implements several abstract methods. When I extend that class I get the following fatal error message:

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

Class CI_Controller_Rest contains 6 abstract methods and must therefore be declared abstract or implement the remaining methods  

The class with abstract 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();
}  

The class where I extend CI_Controller_Rest:

我扩展的类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() {}
}  

What should I do more than this?

除了这些,我还应该做什么?

回答by Wayne Whitty

If a class has one or more abstract functions, 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();
}  

回答by S3Mi

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

回答by Guillermo Hernández

CI_Controller_Rest must be an abstract class because it contains abstract methods

CI_Controller_Rest 必须是抽象类,因为它包含抽象方法

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