PHP致命错误:无法继承抽象函数

前端之家收集整理的这篇文章主要介绍了PHP致命错误:无法继承抽象函数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我不明白我在做错什么
abstract class Css {
    abstract protected function parse($data);
}

abstract class CssElem extends Css {
    abstract protected function parse($data);
}

class Modifier extends CssElem {
    function __construct($data = null) {
        if( $data )
            $this->parse ($data);
    }

    protected function parse($data) {
       // Some code...
    }
}

它给了我

[Mon Jul 8 13:21:10 2013] PHP Fatal error: Can’t inherit abstract
function Css::parse() (prevIoUsly declared abstract in CssElem) in
/home/arthur/NetBeansProjects/capa/CssElem.PHP on line 21 [Mon Jul 8
13:21:10 2013] 127.0.0.1:41207 [500]: / – Can’t inherit abstract
function Css::parse() (prevIoUsly declared abstract in CssElem) in
/home/arthur/NetBeansProjects/capa/CssElem.PHP on line 21

第21行是抽象保护函数解析($data);在CssElem.

我更熟悉Java中的OOP,但根据the doc

尝试将您的中级班改为:
abstract class CssElem extends Css {
    // abstract protected function parse($data); // <-- take this away
}

参见文档中的this comment.

引用来自评论

An abstract class that extends an abstract class can pass the buck to its child classes when it comes to implementing the abstract methods of its parent abstract class.

猜你在找的PHP相关文章