PSR 中命名空间声明之前有多少新行?
How many new lines before namespace declaration in PSR?
PSR 对于命名空间声明后的新行有相当明确的立场:
When present, there MUST be one blank line after the namespace declaration.
但是命名空间之前的空行呢?有什么规则或限制吗?我相信我在某个地方见过一些东西,但现在找不到了。
小节3。 PSR-12 中的 Declare Statements、Namespace 和 Import Statements 讨论了脚本开始的各个部分和状态
The header of a PHP file may consist of a number of different blocks.
If present, each of the blocks below MUST be separated by a single
blank line, and MUST NOT contain a blank line. Each block MUST be in
the order listed below, although blocks that are not relevant may be
omitted.
(强调我的)。
下面还有例子
<?php
/**
* This file contains an example of coding styles.
*/
declare(strict_types=1);
namespace Vendor\Package;
use Vendor\Package\{ClassA as A, ClassB, ClassC as C};
显示间距。
我从中读到的主要内容不是关于定义之前的空行数,而是更多地定义任何组件之间必须有一个空行。
只是关于 PSR-2 的评论,是状态
Deprecated - As of 2019-08-10 PSR-2 has been marked as deprecated.
PSR-12 is now recommended as an alternative.
PSR 对于命名空间声明后的新行有相当明确的立场:
When present, there MUST be one blank line after the namespace declaration.
但是命名空间之前的空行呢?有什么规则或限制吗?我相信我在某个地方见过一些东西,但现在找不到了。
小节3。 PSR-12 中的 Declare Statements、Namespace 和 Import Statements 讨论了脚本开始的各个部分和状态
The header of a PHP file may consist of a number of different blocks. If present, each of the blocks below MUST be separated by a single blank line, and MUST NOT contain a blank line. Each block MUST be in the order listed below, although blocks that are not relevant may be omitted.
(强调我的)。
下面还有例子
<?php
/**
* This file contains an example of coding styles.
*/
declare(strict_types=1);
namespace Vendor\Package;
use Vendor\Package\{ClassA as A, ClassB, ClassC as C};
显示间距。
我从中读到的主要内容不是关于定义之前的空行数,而是更多地定义任何组件之间必须有一个空行。
只是关于 PSR-2 的评论,是状态
Deprecated - As of 2019-08-10 PSR-2 has been marked as deprecated. PSR-12 is now recommended as an alternative.