gpt4 book ai didi

PHP fatal error : Can't inherit abstract function

转载 作者:行者123 更新时间:2023-12-02 21:50:55 25 4
gpt4 key购买 nike

我不明白我做错了什么......

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 行是 CssElem 中的抽象 protected 函数 parse($data);

我对Java中的OOP比较熟悉,但根据the doc似乎还可以...

最佳答案

尝试将您的中级类(class)更改为:

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 version 7.2中被允许:

It is now allowed to override an abstract method with another abstract method in a child class. (https://wiki.php.net/rfc/allow-abstract-function-override)

关于PHP fatal error : Can't inherit abstract function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17525620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com