Basic code specifications
This specification sets out relevant standards for basic elements of code, Keywords "must" ("MUST"), "must not/must not" ("MUST NOT"), "need" ("REQUIRED"), Overview PHP code filesmuststart with PHP code filesmustbe encoded in UTF-8 without BOM; PHP codeshouldonly define declarations such as classes, functions, constants, etc., or other operations that will produce subordinate effects (such as generating file output and modifying .ini configuration files, etc.). You can only choose one of the two; Namespaces and classesmustcomply with PSR's autoloading specification: one of PSR-0[]; The naming of classesmustfollow the StudlyCaps CamelCase naming convention starting with an uppercase letter; All letters of the constants in the class must be in uppercase letters, and words should be separated by underscores; The method namemust conform to the camelCase naming convention of starting with lowercase camelCase. File2.1. PHP tags PHP code mustuse long tag or short output tag; = ?> mustand can only use UTF-8 encoding without BOM. 2.3. Subordinate effects (side effects) In a PHP file,should either only define new declarations, such as classes, functions or constants, and other operations that do not produce dependency effects, or only logical operations that will produce dependency effects, but should not both at the same time Has both. The term "side effects" means logical operations performed only by including files without directly declaring classes,functions, constants, etc. The following is a counter-example, a code that contains declarations and produces dependency effects:
Namespace and class naming must follow [PSR-0][]. According to the specification, each class is an independent file, and the namespace has at least one level: the top-level organization name (vendor name). Class naming must follow the StudlyCaps camel case naming convention starting with an uppercase letter. Code for PHP 5.3 and later versions mustuse the official namespace. For example:
You should use pseudo namespace writing, and the convention is to use the top-level organization name (vendor name) such as Vendor_ as the class prefix. // How to write 5.2.x and previous versions
Constants, properties and methods of the class"Class" here refers to all classes, interfaces and reusable code blocks (traits) 4.1. Constants All letters in class constants must becapitalized, and words are separated by underscores. Refer to the following code: namespace VendorModel;
4.2. Properties
The attribute naming of the class can follow the camel case starting with upper case ($StudlyCaps), the camel case starting with lower case ($camelCase), or the underline delimited format ($under_score). This specification does not make it mandatory, but no matter which naming is followed Methods should all be consistent within a certain range. This scope can be the entire team, the entire package, the entire class, or the entire method. 4.3. Method The method name mustconform to the camelCase()-style camelCase naming convention starting with lowercase. Reposted from Github(PizzaLiu) |