to understand and master a programming language, I think it is important to master its naming rules. No rules. Inadequate surrounding area, programming is the same, not only you can understand, others should also be able to understand your code, it is necessary to master the language of the naming rules. From the programmer to write the code used by the naming rules, you can see at a glance at the technical level of the programmer. This article and everyone to share is the PHP language naming rules, hope can help you better learn php, come together to see it.
As a general rule, the names of classes, functions, and variables should be able to make it easy for code readers to know what the code does, and avoid using the ambiguous nomenclature.
1. class naming
① uses uppercase letters as the word's segmentation, and the other letters use lowercase.
② The first letter of the name with uppercase.
③ do not use underscore ('_').
such as: Name,Superman,bigclassobject.
2. class attribute naming
the ① attribute name should be prefixed with the character ' m ' .
the ② prefix ' m ' followed by a rule that is consistent with the class naming.
③ ' m ' always modifies at the beginning of the name, as if it were a reference to the beginning of ' R ' .
such as:mvalue,mlongstring , etc.
3. naming the method
The function of the ① method is to perform an action to achieve a purpose. So the name should indicate what the method is. The prefix of the general name is the first rule, such as is (judgment),get(get),set(setting).
The ② method names the first word in lowercase, followed by the first letter of the word ... such as:
4. parameter naming in methods
① The first character uses lowercase letters.
② All characters after the first character are capitalized by the first character of the class naming convention.
Such as:
5. Reference Variables
① reference variable to be prefixed with ' R ' . such as:
6. variable naming
① use lowercase for all letters.
② uses ' _ ' as the demarcation of each word.
such as:$msg _error,$chk _pwd and so on.
③ Temporary variables are usually named i,J,k, M and n, which are generally used for integral types;c,d,E ,s They are generally used for character types.
The ④ instance variable is preceded by an underscore, the first lower case, and the first letter of the remaining words capitalized.
7. Global Variables
① Global variables should be prefixed with ' G '. such as:global $gTest.
8. constants, global constants
① constants, global constants, should all use uppercase letters, between words with ' _ ' to split. such as:
9. Static Variables
① Static variables should be prefixed with ' s '. such as:
function Naming
① All the names are in lowercase letters and multiple words are split with ' _ ' . such as:
The various naming conventions above can be combined together to use, such as:
Article Source: Pinterest
Naming conventions for PHP languages