PHPDoc:@return void 有必要吗?

标签 php return-value phpdoc

真的有必要这样做吗:

/**
 * ...
 * 
 * @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 description

The @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/

相关文章:

http - 如何使用从批处理脚本调用的 curl 获取 http post 请求的响应代码?

php - 如何记录 PHPUnit 测试

php - 如何在 PhpDoc 文档 block 中使用 NetBeans 和 SVN @version 标记?

PHP 预匹配?如何返回不匹配的字符?

php - Mandrill 未设置内联 css

PHP DOM 在没有 DOMDocumentFragment::appendXML 的情况下将 HTML 附加到现有文档

c - system() 函数从守护进程返回值始终为 -1

javascript - 我在页面加载时将整个 $_SESSION 变量放入 json 对象中。虽然这对我有用,但这是一个好的做法吗?

java - 访问不同情况下的返回值

beta - phpdocumentor 2 未完成文档