1.5 PSR Coding Standards
1.5.1 Overview
- PSR is PHP Standard Recommendations shorthand, developed by PHP PHP FIG Organization norms, standards of practice are developed in PHP.
- It has been voted by six sets of standards, and support has been recognized by most of the PHP framework.
- URL: http: //psr.phphub.org/
1.5.2 PSR-1 encoding specifications based
1、PHP代码文件 必须 以 <?php 或 <?= 标签开始
2、类的命名大写开头的驼峰命名规范
3、类中的常量所有字母都必须大写,单词间用下划线分隔
4、方法名称必须符合小写开头驼峰命名规范5、
Side effects: (side effects), a file only one thing, if you do something that produces side effects
It does not produce side effects: a file only one thing
Side effects: a file do multiple things
1.5.3 PSR-2 coding style specification
代码 必须 使用 4 个空格符而不是「Tab 键」进行缩进
每个 namespace 命名空间声明语句和 use 声明语句块后面,必须 插入一个空白行
类的开始花括号({) 必须 写在类声明后自成一行,结束花括号(})也 必须 写在类主体后自成一行
方法的开始花括号({) 必须 写在函数声明后自成一行,结束花括号(})也 必须 写在函数主体后自成一行。
类的属性和方法 必须 添加访问修饰符(private、protected 以及 public),abstract 以及 final 必须 声明在访问修饰符之前,而 static 必须 声明在访问修饰符之后。