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

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).

图片转代码服务由CSDN问答提供 功能建议

我目前使用这样的注释顺序:

代码1:

  / ** 
 *设置main(top),secondary(sub1)level和tertiary(sub2)级别的元素; 
 *阻止与先前实例共享内容
  * 
 * @param string $ TopElement 
 * @param string $ SubElement1 
 * @param string $ SubElement2 
 * 
 * @return void 
 * 
 * @throws MarC_Exception如果未设置top元素\  n * @throws MarC_Exception如果未设置sub1元素
 * @throws MarC_Exception如果没有设置sub2元素
 * @throws MarC_Exception如果所有元素都设置相同
 * / 
 
共和函数__construct($ TopElement =“”  ,$ SubElement1 =“”,$ SubElement2 =“”)
 {
 ... 
} 
   
 
 

代码2: / ** *用于创建代码的元素 * * @static * @var array * / nprotected $ Elements = array(); < 代码3:

  / ** 
 * @package ...  ... 
 * @copyright ... 
 * 
 * @license ...  
 * 
 *生成高级选择菜单
 * / 
   
 
 

此时我不使用所有注释(可能我使用的所有注释都可以看到 在上面的代码中。

我想知道在php中是否有任何建议(优先)的注释顺序 - 或者它是程序员的自由问题(然后这个问题将毫无用处)。< / p>

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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.

    打赏 评论

相关推荐 更多相似问题