PHPEncoding naming rules
Class
A class name is a noun. It is a combination of uppercase and lowercase letters. Try to make your class name concise and descriptive. Use a complete word to avoid acronyms (unless it is more widely used, such as URL or HTML)
Class raster;
Class imagesprite
Before naming a class, you must first know the functions of the class. If the clue provided by the class name cannot accurately reflect the class function, the name fails.
A mixed name composed of more than three words is prone to confusion between various entities in the system. Try to use (CRC session card) to see if the entity corresponding to the name has so many functions.
Naming a derived class should avoid the temptation to include its parent class name. The name of a class is only related to itself and has nothing to do with its parent class.
Sometimes suffix names are useful. For example, if your system uses an agent, you can name a part as the DownloadAgent for real information transfer.
Class attribute name
The attribute name should be prefixed with the character 'M.
The prefix 'M' is based on the same class naming rules.
'M' always acts as a modifier at the beginning of the name, just like a reference starting with 'R.
Reason
The prefix 'M' prevents any burst of class attributes and method names. Your method name and attribute name are often very similar, especially for accessing elements.
For example
Class nameonetwo
{
Int $ mvarabc;
Int $ merrornumber;
String $ mrname;
}
LetterQuantity
The method name is a verb. It is a combination of upper and lower cases. The first letter of the first word is lowercase, And the last letter of the last word is capitalized.
Function run ();
Function runfast ();
Function getbackground ();
Generally, each method executes an action, so the name of it should clearly indicate what it is doing: replace errorcheck () with checkforerrors (), and use dumpdatatofile () replace datafile (). In this way, functions and data can also be differentiated.
Sometimes suffix names are useful:
Max-indicates the maximum value that an object can assign.
CNT-the current value of a running count variable.
Key-key value.
For example, retrymax indicates the maximum number of retries, and retrycnt indicates the current number of retries.
Sometimes prefix names are useful:
Is-it means to ask a question about something. At any time, people will know that this is a problem.
Get-Indicates obtaining a value.
Set-meaning to set a value
Example: ishitretrylimit
Variable
Except for the variable name, all instances, including Class and Class constants, are case-insensitive. The first letter of the first word is lowercase, and the first letter of the subsequent word is capitalized. Variable names should not start with an underscore or dollar sign, although this is syntactically allowed.
The variable name should be brief and descriptive. The selection of variable names should be easy to remember, that is, they can point out their purposes. Avoid the variable name of a single character unless it is a one-time temporary variable. Temporary variables are usually named I, J, K, M, and N. They are generally used for integer type; C, D, E, they are generally used for struct type.
Char $ C;
Int $ I;
Float $ mywidth;
Instance variables
The case-sensitive rule is similar to the variable name, except for the preceding underline.
Int $ _ employeeid;
String $ _ name;
Customer $ _ customer;
Constant
The declaration of class constants and ANSI constants should be in uppercase and words should be separated by underscores. (Avoid ANSI constants whenever possible, which may cause errors)
Static final int $ min_width = 4;
Static final int $ max_width = 999;
Static final int $ get_the_cpu = 1;