dscojuxf69080 2015-11-21 13:59
浏览 66
已采纳

PHPStorm 9对类继承的检查工作是不可取的

I'm facing the following issue in PHPStorm 9:
Say I have an interface FieldInterface that has some methods:

namespace Acme;

interface FieldInterface {
    public function methodA();
    public function methodB();
}

then I have an abstract class that implements base functionality of the interface. That abstract class has the user to implement certain methods, let's say it's methodB in our example:

namespace Acme;

abstract class AbstractField implements FieldInterface {
    public function methodA() {
        // implement methodA
    }

    public abstract function methodB(); // have the user implement it
}

And finally I have some ready-to-use class StringField:

namespace Acme;

class StringField extends AbstractField {
    public function methodB() {
        // implement methodB
    }
}

At this point everything's going well. But if I add new method in the FieldInterface, PHPStorm does not say that anything is wrong with AbstractField while it's obvious that I should add public abstract function newMethod(); in there. However, it spots the error in StringField class instead.
It could be understood from the point that abstract classes are made for the purpose of extention, but usually you extend the abstract class rather than implement underlying interface. The whole meaning of making abstract class is to save user's time for implementing the interface. So why PHPStorm forces me to implement interface in concrete class rather than forcing me to implement it in abstract class that is explicitly implements the interface.
So I wonder if it is a bug in PHPStorm, or maybe it's done on purpose. Either way, is there any workaround?

  • 写回答

1条回答 默认 最新

  • dqby43944 2015-11-23 19:18
    关注

    That's how it should be, showing an error in the abstract class would be wrong.

    In fact, public abstract function methodB(); is redundant because the abstract class already "inherits" this abstract method from the interface as it does not implement it.

    The only workaround is to make AbstractField not abstract.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)