Moving PHP forward through collaboration and standards.--fig
PSR-1: Basic Coding Standard
基础编码标准
PHP 文件只能使用 <?php 和 <?= tags 这两种标签
PHP 文件只能使用 无 BOM 头 的 UTF-8 编码.
PHP 源文件建议要么只用作声明 (类, 方法, 常量, etc.) 要么处理副作用 (比如 输出信息, 修改 .ini 设置项, etc.) 不建议两者同时进行.
命名空间和类必须遵守 PSR: [PSR-0, PSR-4 (自动加载) ] 规范.
类名必须遵守大驼峰 (studlyCaps) 命名规范.
类内常量 (Class constants) 必须由大写字母(uper case) 和下划线(underscore separators) 组成。
方法名必须遵守小驼峰(camelCase)命名规范.
PSR-2: Coding Style Guide
编码风格导航
代码必须遵 PSR [PSR-1] 规范.
代码必须使用 4 个空格缩进,而不是制表符(tabs).
不严格限制代码长度; 宽松限制在 120 字符, 但是建议每行限制在 80 字符之内.
命名空间申明之后必须空行, use 申明必须在命名空间申明的空行之后使用(二者保持一个空行距离).
Opening braces for classes MUST go on the next line, and closing braces MUST go on the next line after the body.
Opening braces for methods MUST go on the next line, and closing braces MUST go on the next line after the body.
Visibility MUST be declared on all properties and methods; abstract and final MUST be declared before the visibility; static MUST be declared after the visibility.
Control structure keywords MUST have one space after them; method and function calls MUST NOT.
Opening braces for control structures MUST go on the same line, and closing braces MUST go on the next line after the body.
Opening parentheses for control structures MUST NOT have a space after them, and closing parentheses for control structures MUST NOT have a space before.
PSR-3: Logger Interface
日志接口
PSR-4: Autoloader
自动加载规范
This PSR describes a specification for autoloading classes from file paths. It is fully interoperable, and can be used in addition to any other autoloading specification, including PSR-0. This PSR also describes where to place files that will be autoloaded according to the specification.
Post Views:
38