douxie2029 2010-01-14 01:09
浏览 130
已采纳

PHPDoc:@return void必要吗?

Is it really necessary do something like this:

/**
 * ...
 * 
 * @return void
 */

I have quite a few methods that don't have a return value, and it seems really redundant to put something like this in the comment. Would it be considered bad form to leave it out?

  • 写回答

5条回答 默认 最新

  • dongtong5242 2010-01-14 01:11
    关注

    If it makes it clear for the documentation, then leave it in, but it isn't strictly necessary. It's an entirely subjective decision.

    Personally, I would leave it out.

    EDIT
    I stand corrected. After a little googling, the wikipedia page says:

    @return [type description] This tag should not be used for constructors or methods defined with a void return type.

    The phpdoc.org website says:

    @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... Based on that, I would say leave out the void. It's non-standard, at least.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳