php psr-4 编码规范,PHP代码规范-PSR[1-4]精简版

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值