Does PSR-2 require vertical alignment?

☆樱花仙子☆ 提交于 2019-12-10 02:42:02

问题


What is allowed between these two:

$value = 'value';
$user = 'John';
$timestamp = 1480927909;
$day = date('Y-m-d', $timestamp);

or

$value     = 'value';
$user      = 'John';
$timestamp = 1480927909;
$day       = date('Y-m-d', $timestamp);

回答1:


PSR-2 does not have specific rules for this kind of inter-line alignment:

From the PSR-2 Conclusion:

There are many elements of style and practice intentionally omitted by this guide. These include but are not limited to:

  • Declaration of global variables and global constants
  • Declaration of functions
  • Operators and assignment
  • Inter-line alignment
  • Comments and documentation blocks
  • Class name prefixes and suffixes
  • Best practices

Future recommendations MAY revise and extend this guide to address those or other elements of style and practice.

For what it's worth, inter-line alignment was discussed for PSR-1 by the PHP-FIG Group, but was removed from the final version:

The way-back original long-form PSR-1 covered inter-line alignment, globals, ternaries, assignment, and lots of other things. Those ended up getting removed for various reasons; their epitaph is at the conclusion of PSR-2.



来源:https://stackoverflow.com/questions/40970453/does-psr-2-require-vertical-alignment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!