PHP-FIGPSR-1 # basic coding standards this standard contains a standard encoding element for ensuring the interoperability of PHP shared code.
The key words "MUST", "must not", "REQUIRED needs", "SHALL will", "shall not will NOT", "shoshould ", "shoshould NOT", "RECOMMENDED by RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
Overview
- File must use <? Php and <? = Tag.
- The PHP code in the file must be encoded using a non-BOM header UTF-8.
- Files can declare "symbols" (such as classes, functions, constants, and so on), and can also perform marginal effects (such as generating output and changing ini settings .). But these two types of things should not appear in the same file.
- The namespace and class must follow the "autoloading" PSR: [PSR-0, PSR-4].
- The class name must be declared using StudlyCaps (upper-case camper.
- Class constants must use uppercase letters separated by underscores.
- The method name must use the hump declaration.
File PHP tag
PHP code must use long labels <? Php?> Or echo short tag <? =? >; Other labels must not be used.
Character encoding
PHP code must be encoded using a UTF-8 without BOM header
Marginal effect
A file (should) either declares symbols (classes, functions, constants, etc.), and cannot cause any marginal effect; or executes code that produces marginal effects. These two cases cannot appear in a file.
The "marginal effect" executes logics unrelated to declarative classes, functions, and constants.
Marginal effects include but are not limited to: generating output, explicit require or include, connecting to external services, modifying ini configurations, issuing errors or exceptions, and modifying global or static variables, read and write files.
The following is an example of declarative symbols that produce marginal effects. This should be avoided:
\ N "; // declare function foo () {// function body}
The following example only contains declarations with no marginal effect. it is worth following:
Namespace name and class nameThe namespace name and class name must follow the "autoloading" PSR: [PSR-0, PSR-4].
This means that each file can only contain one class and has at least one namespace: top-level vendor name.
The class name must be declared using StudlyCaps (upper-case camper.
For PHP 5.3 and later versions, you must use a formal namespace (before PHP 5.3, namespace is not supported ).
For example:
Class constants, attributes, and methodsThe "classes" here include classes, interfaces, and traits.
4.1. constant
Class constants must be declared in uppercase using underscores.
AttributeThis guide avoids the preference of StudlyCaps, camelCase, and $ under_score for any attribute naming style.
No matter which naming style is used, it should be consistent within a reasonable range. The range can be set to "vendor-level", "package-level", "class-level", or "method-level.
MethodCamelCase () must be used for method names ().