简体   繁体   English

PHP中的继承与抽象方法

[英]Inheritance in php with abstract methods

I try to inherit from an abstract class to an abstract class: 我尝试从抽象类继承到抽象类:

abstract class Android{
    public $description="unknown brand";
    public function __construct() {

    }
    public function get_description(){
        return $this->description;
    }    
    public abstract function cost();
}

abstract class FeaturesDecorator extends Android {
    public abstract function get_description();
}

I get this error: 我收到此错误:

Fatal error: Cannot make non abstract method Android::get_description() abstract in class FeaturesDecorator in C:\\xampp\\htdocs\\jPlugin\\DesignPatterns\\Decorator\\Decorator.php on line 65 致命错误:无法在第65行上的C:\\ xampp \\ htdocs \\ jPlugin \\ DesignPatterns \\ Decorator \\ Decorator.php中的FeatureFeature类中使非抽象方法Android :: get_description()抽象

why? 为什么? what ruins the inheritance? 是什么破坏了继承?

函数get_description已在您的父类中定义并声明,您不能在子代中使其抽象化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM