PHP Fatal error: Can't inherit abstract function

后端 未结 4 1697
一生所求
一生所求 2020-12-18 22:10

I don\'t understand what I\'m doing wrong...

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

abstract class CssElem extends Css {
    a         


        
4条回答
  •  时光说笑
    2020-12-18 22:32

    Try changing your intermediate class to:

    abstract class CssElem extends Css {
        // abstract protected function parse($data); // <-- take this away
    }
    

    See also this comment in the docs.

    Quoting from the 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.

    It seems however that this will be allowed in the next 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)

提交回复
热议问题