dongzhang8475 2015-01-19 21:53
浏览 41
已采纳

PHP中注释顺序的建议

I currently use such order of annotations:

Code 1:

/**
 * sets elements for main (top), secondary (sub1) level and tertiary (sub2) level;
 * prevents sharing of content with previous instances
 *
 * @param string $TopElement
 * @param string $SubElement1
 * @param string $SubElement2
 *
 * @return void
 *
 * @throws MarC_Exception if top element was not set
 * @throws MarC_Exception if sub1 element was not set
 * @throws MarC_Exception if sub2 element was not set
 * @throws MarC_Exception if all elements were set the same
 */
public function __construct($TopElement="", $SubElement1="", $SubElement2="")
{
 ...
}

Code 2:

/**
 * elements used for creation of code
 *
 * @static
 * @var array
 */
protected $Elements = array();

Code 3:

/**
 * @package ...
 *
 * @author ...
 * @copyright ...
 *
 * @license ...
 *
 * generation of advanced select menu
 */

At this time i don't use all annotations (probably all I use you can see in codes above).

And I wonder if in php is any suggested (preffered) order of annotations - or it is free matter of programmer (and then this question will be useless).

  • 写回答

1条回答 默认 最新

  • dream0776 2015-01-19 22:04
    关注

    TLDR; It's a free matter

    PHP coding standards differ on this. The best I can suggest is to pick a coding standard you like and run PHP CodeSniffer (https://github.com/squizlabs/PHP_CodeSniffer) against it and see what it suggest. Some coding standards require they be in a specific order and a specific spacing to your docblock annotations. Others are more relaxed and make no suggestions about docblock annotations what-so-ever.

    To get PHP Code Sniffer:

    $ curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
    $ php phpcs.phar -h
    $ php phpcs.phar --standard=[STANDARD_CHOICE] /path/to/project
    

    Some coding standards you might want to consider:

    If you're worried about a document generators (like phpDocumentor) not being able to parse the docblock annotations, you can always check what annotations they support. I've never had a problem with phpDocumentor complaining about the ordering or formatting though.

    As for custom annotations being used by libraries such as Doctrine, Symfony and PHPUnit, I've also never noticed the order having an impact on the parsing and processing.

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

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大