首页 后端开发 php教程 PHP(五)Code Standard

PHP(五)Code Standard

Jun 13, 2016 pm 12:16 PM
after class must namespace the

PHP(5)Code Standard

PHP(5)Code Standard

?

?

1. Autoloading Standard

?

Mandatory

?

\\()*

?

?

?

Underscores in Namespaces and Class Names

?

Actually, underscore means another directory for class name.

?

?

?

example

?

\namespace\package\Class_Name => /path/to/project/lib/vendor/namespace/package/Class/Name.php

?

\namespace\package_name\Class_Name => /path/to/project/lib/vendor/namespace/package_name/Class/Name.php

?

?

?

Here is how we load the PHP class.

?

https://gist.github.com/jwage/221634

?

?

?

2. Basic Coding Standard

?

PHP code MUST use only UTF-8 without BOM.

?

?

?

3. Coding Style Guide

?

Code MUST use 4 spaces for indenting, not tabs.

?

?

?

Learn from one colleague, In Sublime, click on the line, we saw “Tab Size” at the bottom.

?

?

?

We can go to [View]>[Indentation]>Convert Indentation to Space and check [Indent Using Space]

?

?

?

There MUST be one blank line after the namespace declaration, and there MUST be one blank line after the block of use declarations.

?

?

?

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;

?

?

?

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 controller structures MUST NOT have a space after them, and closing parentheses for control structures MUST NOT have a space before.

?

?

?

The closing ?> tag MUST be omitted from files containing only PHP.

?

?

?

There MUST NOT be trailing whitespace at the end of non-blank lines.

?

?

?

Blank lines MAY be added to improve readability and to indicate related blocks of code.

?

?

?

PHP keywords and True/False/Null MUST be in lower case. true, false, null.

?

?

?

all use declarations MUST go after the namespace declaration.

?

?

?

Visibility MUST be declared on all properties.

?

?

?

The var keyword MUST NOT be used to declare a property.

?

?

?

There MUST NOT be more than one property declared per statement.

?

?

?

4. Logger Interface

?

?

?

?

?

?

?

References:

?

http://www.php-fig.org/psr/psr-1/

?

http://www.php-fig.org/psr/psr-0/

?

http://www.php-fig.org/psr/psr-2/

?

?

?

?

?

?

?

?

?

?

?

?

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门文章

两个点博物馆:邦格荒地地点指南
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章

两个点博物馆:邦格荒地地点指南
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章标签

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

Python中的class类和method方法的使用方法 Python中的class类和method方法的使用方法 Apr 21, 2023 pm 02:28 PM

Python中的class类和method方法的使用方法

2 个月不见,人形机器人 Walker S 会叠衣服了 2 个月不见,人形机器人 Walker S 会叠衣服了 Apr 03, 2024 am 08:01 AM

2 个月不见,人形机器人 Walker S 会叠衣服了

使用jQuery替换元素的class名称 使用jQuery替换元素的class名称 Feb 24, 2024 pm 11:03 PM

使用jQuery替换元素的class名称

python中class是什么意思 python中class是什么意思 May 21, 2019 pm 05:10 PM

python中class是什么意思

SpringBoot怎么通过自定义classloader加密保护class文件 SpringBoot怎么通过自定义classloader加密保护class文件 May 11, 2023 pm 09:07 PM

SpringBoot怎么通过自定义classloader加密保护class文件

如何解决 golang 中的 "undefined: template.Must" 错误? 如何解决 golang 中的 "undefined: template.Must" 错误? Jun 24, 2023 pm 09:00 PM

如何解决 golang 中的 "undefined: template.Must" 错误?

java的预定义Class对象的方法 java的预定义Class对象的方法 Jul 01, 2023 pm 06:41 PM

java的预定义Class对象的方法

PHP Class用法详解:让你的代码更清晰易读 PHP Class用法详解:让你的代码更清晰易读 Mar 10, 2024 pm 12:03 PM

PHP Class用法详解:让你的代码更清晰易读

See all articles