Moving PHP forward through collaboration and standards.–fig

PSR-1: Basic Coding Standard

基础编码标准

  1. PHP 文件只能使用 <?php 和 <?= tags 这两种标签

  2. PHP 文件只能使用 无 BOM 头 的 UTF-8 编码.

  3. PHP 源文件建议要么只用作声明 (类, 方法, 常量, etc.) 要么处理副作用 (比如 输出信息, 修改 .ini 设置项, etc.) 不建议两者同时进行.

  4. 命名空间和类必须遵守 PSR: [PSR-0, PSR-4 (自动加载) ] 规范.

  5. 类名必须遵守大驼峰 (studlyCaps) 命名规范.

  6. 类内常量 (Class constants) 必须由大写字母(uper case) 和下划线(underscore separators) 组成。

  7. 方法名必须遵守小驼峰(camelCase)命名规范.

PSR-1

PSR-2: Coding Style Guide

编码风格导航

  1. 代码必须遵 PSR [PSR-1] 规范.
  2. 代码必须使用 4 个空格缩进,而不是制表符(tabs).
  3. 不严格限制代码长度; 宽松限制在 120 字符, 但是建议每行限制在 80 字符之内.
  4. 命名空间申明之后必须空行, use 申明必须在命名空间申明的空行之后使用(二者保持一个空行距离).
  5. Opening braces for classes MUST go on the next line, and closing braces MUST go on the next line after the body.
  6. Opening braces for methods MUST go on the next line, and closing braces MUST go on the next line after the body.
  7. 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.
  8. Control structure keywords MUST have one space after them; method and function calls MUST NOT.
  9. Opening braces for control structures MUST go on the same line, and closing braces MUST go on the next line after the body.
  10. 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-2

PSR-3: Logger Interface

日志接口

PSR-3

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.

PSR-4

临时

Hello world!
文章已创建 211

发表评论

电子邮件地址不会被公开。 必填项已用*标注

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部