dongxunhua2054 2016-05-03 00:15
浏览 40
已采纳

对于抽象函数,是应该为抽象函数,实现函数还是两者定义phpdoc?

Is there a correct or standard way to do this?

For example:

AbstractFoo.php:

abstract class AbstractFoo {
    /**
     * Does the phpdoc go here?
     */
    public function fooFunction();
}

Foo.php:

class Foo extends AbstractFoo {
    /**
     * Or does the phpdoc go here?
     */
    public function fooFunction(){
        // some implementation
    }
}

Consider the following issues:

  • If you put the phpdoc in the abstract FooFunction(), and control + click $foo->FooFunction(), you will end up at the Foo class' FooFunction(), which is undocumented, and not immediately obvious that it's implementing an abstract function. And if it was obvious, there's no easy way to get to the phpdoc in the abstract function, without

    • Determining what class the object was
    • Locating the abstract class it is inheriting
    • Doing a "find" on the function name in that abstract class
  • If you put the phpdoc only in the children functions, then you're faced with duplicating phpdocs across the children functions of n number of inheriting classes.

  • If you put the phpdoc in both, the abstract function's phpdoc becomes purposeless, unless a child class did not have a phpdoc, wanting to inherit the abstract's phpdoc. But even in this case, again, there's no easy way to navigate to that abstract phpdoc.

  • 写回答

1条回答 默认 最新

  • douzuan5365 2016-05-03 00:55
    关注

    You should document an interface or abstract implementation. Otherwise, use @inheritdoc/document your implementation of an interface method.

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

报告相同问题?

悬赏问题

  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考