- Class Nameonetwo
- Class Name
Copy Code
2. Naming of class libraries
Currently, namespaces are being used more and more extensively to avoid conflicting class names between different vendors and groups of libraries. When namespaces are not yet in place, in order to avoid class name collisions, it is common practice to prefix the class name with a unique, two-character, and certainly a better one. For example:
- John Johnson's data structure class library can be prefixed with JJ, as follows:
- Class Jjlinklist
- {
- }
Copy Code
3. Naming of methods
Using rules that are consistent with class naming also uses English words to interpret the method. For example:
- Class Nameonetwo
- {
- function DoIt () {};
- function HandleError () {};
- }
Copy Code
4. Naming of class attributes
Attribute naming should be prefixed with the character ' M '. The prefix ' m ' is followed by a rule with a consistent class naming. ' m ' always modifies at the beginning of the name, as if it were a reference to the beginning of ' R '. The prefix ' m ' prevents any conflicts between class properties and method names. Your method name and attribute name are often very similar, especially for accessing elements. For example:
- Class Nameonetwo
- {
- function Varabc () {};
- function ErrorNumber () {};
- var mvarabc;
- var Merrornumber;
- var mrname;
- }
Copy Code
5. Naming the parameters in the method
The first character uses a lowercase letter. All words after the first character are capitalized by the first character of the class naming convention. You can do this at any time to know which variable corresponds to which variable. In addition, this can be done with a name similar to the class name without conflicting duplicate names. For example:
- Class Nameonetwo
- {
- function Startyourengines (
- & $rSomeEngine,
- & $rAnotherEngine);
- }
Copy Code
6, the name of the variable
All letters are used in lowercase. Use ' _ ' as the demarcation of each word. In many PHP tutorials, it is said. In this way, the scope of the variables in the code is clear. All variables look different in the code and are easily recognizable. For example:
- function HandleError ($errorNumber)
- {
- $error = Oserr ();
- $time _of_error = oserr->gettimeoferror;
- $error _processor = oserr->geterrorprocessor;
- }
Copy Code
7. Naming Global variables
Global variables should be prefixed with ' G '. It is important to know the scope of a variable. For example:
- Global $gLog;
- Global & $grLog;
Copy Code
8. Naming of functions
The function name uses the C GNU convention, with all letters using lowercase letters, using ' _ ' to split the words. This makes it easier to distinguish between the associated class names. For example:
- function Some_bloody_function ()
- {
- }
Copy Code |