真的有必要这样做吗:
/**
* ...
*
* @return void
*/
我有很多方法没有返回值,在评论中放这样的东西似乎真的是多余的。将其排除在外会被认为是不好的形式吗?
最佳答案
如果文档清楚,则保留它,但这不是绝对必要的。这是一个完全主观的决定。
就我个人而言,我会忽略它。
编辑
我站得更正了。经过一番谷歌搜索,wikipedia page说:
@return [type description] This tag should not be used for constructors or methods defined with a void return type.
phpdoc.org 网站说:
@return datatype description
@return datatype1|datatype2 descriptionThe @return tag is used to document the return value of functions or methods. @returns is an alias for @return to support tag formats of other automatic documentors
The datatype should be a valid PHP type (int, string, bool, etc), a class name for the type of object returned, or simply "mixed". If you want to explicitly show multiple possible return types, list them pipe-delimited without spaces (e.g. "@return int|string"). If a class name is used as the datatype in the @return tag, phpDocumentor will automatically create a link to that class's documentation. In addition, if a function returns multiple possible values, separate them using the | character, and phpDocumentor will parse out any class names in the return value. phpDocumentor will display the optional description unmodified.
Sooo...基于此,我会说离开空白。至少它是非标准的。
关于PHPDoc:@return void 有必要吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2061550/