【问题标题】:How to correctly document aliased object types?如何正确记录别名对象类型?
【发布时间】:2017-10-18 16:37:16
【问题描述】:

如果我在别名下导入了一个类:

use My\Other\ClassName as OtherClass;

我应该如何记录该类的类型?我是否使用别名?

a) @return \My\Other\ClassName

b) @return OtherClass

c)另一种方式?

【问题讨论】:

    标签: php namespaces phpdoc


    【解决方案1】:

    PHPDoc 支持完全限定类、相关类、别名和对自身的引用(静态、$this)

    http://docs.phpdoc.org/guides/types.html

    我见过的最常见的做法是使用完全限定的类名(例如 \My\Other\ClassName),在我看来,这是记录外部类的最佳方式,因为阅读 doc 块的人没有在不同的地方查看 OtherClass 所指的内容。

    如果用phpstorm,看看我最近问的一个问题:Disable import of classes for PHPDoc

    【讨论】:

    • 我同意为了清楚起见,使用完全限定名称更有意义。谢谢。
    猜你喜欢
    • 2022-06-27
    • 2011-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多