Home >Backend Development >PHP Tutorial >Detailed introduction to php naming rules
2. Naming of class library Currently, namespaces are being used more and more widely to avoid class name conflicts between class libraries of different vendors and groups. When namespaces have not yet been adopted, in order to avoid class name conflicts, the general approach is to add a unique prefix before the class name. Two characters is enough. Of course, it would be better to use more. For example:
3. Naming of methods Adopt the same rules as class naming, and also use English words to explain the function of the method. For example:
{ function VarAbc() {};function ErrorNumber() {}; var mVarAbc; var mErrorNumber class NameOneTwo var mrName;
6. Naming of variables Use lower case for all letters. Use '_' as a delimiter for each word. Many PHP tutorials say this.
In this way, the scope of variables in the code is clear. All variables look different in the code and are easily identifiable.
For example: cessor; }
Copy Code 7. Naming of global variables Global variables should be prefixed with ‘g’.
It is very important to know the scope of a variable.
For example: Copy code
The function name follows the C GNU convention, all letters are lowercase letters, and '_' is used to separate words. This makes it easier to distinguish related class names. For example:
|