我不明白我在做错什么
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 …
尝试将您的中级班改为:
原文链接:https://www.f2er.com/php/140076.htmlabstract 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.