> 백엔드 개발 > PHP 튜토리얼 > PHP(五)Code Standard

PHP(五)Code Standard

WBOY
풀어 주다: 2016-06-13 12:16:32
원래의
1961명이 탐색했습니다.

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/

?

?

?

?

?

?

?

?

?

?

?

?

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿