2012-10-02 81 views
9

我有一個類實現了幾個抽象方法。當我繼承了該類我得到以下致命錯誤消息:錯誤:類必須聲明爲抽象或實現其餘方法

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

錯誤告訴你soution CI_Controller_Rest必須是一個抽象類!沒有太多要添加...你必須聲明該類(CI_Controller_Rest)爲抽象的,否則你必須提供該方法的實現... – obe6

+1

@ obe6哦!我怎麼錯過了?我以爲我改變了CI_Controller_Rest來抽象。對! – Andrew

回答

20

如果一個類有一個或多個抽象功能,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(); 
} 
+3

呃,你快了10秒:) – S3Mi

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

請不要在沒有解釋的情況下發布代碼 – JvdBerg

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(); 
} 
相關問題