A file SHOULD declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it SHOULD execute logic with side effects, but SHOULD NOT do both.
PHP代码中应该只定义类、函数、常量等声明,或其他会产生 从属效应 的操作(如:生成文件输出以及修改.ini配置文件等),二者只能选其一;
1
2
3
4
5
6
7
8
9
<?php
class Text
{
public function test ()
{
test;
}
}
1
2
3
4
5
6
7
8
9
10
<?php
class Text
{
public function test ()
{
test;
}
}
Each class must be in a namespace of at least one level(a top-level vendor name)
根据规范,每个类都独立为一个文件,且命名空间至少有一个层次:顶级的组织名称(vendor name)
1
2
3
4
5
6
7
8
<?php
namespace Vendor \Model ;
class Foo
{
}
Class name “A_B_C_D” is not in camel caps format
类的命名要遵循大写开头的驼峰命名规范
参数以分布在多行,随后的行应该缩进一次。如果这么做,第一项应该 在下一行,而且每一个参数独占一行;
1
2
$className->funcName($param1, $param2, $param3mayhaveaveryverylongnamelongerthen120words);
1
2
3
4
5
6
$className-> funcName(
$param1,
$param2,
$param3mayhaveaveryverylongnamelongerthen120words
);