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
- Use uppercase letters for the segmentation of words, and all other letters in lowercase.
- The first letter of the name is capitalized.
- Do not use underline ('_').
- such as: Name, Superman, Bigclassobject.
2. Class attribute naming
- Attribute naming should be prefixed with the character ' M '.
- The prefix ' m ' is 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 a 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 first letter of the name of the method is lowercase, followed by the initials of the word: Such as:
1234567 |
class StartStudy{
//设置类
$mLessonOne
=
""
;
//设置类属性
$mLessonTwo
=
""
;
//设置类属性
function
getLessonOne(){
//定义方法,得到属性mLessonOne的值
...
}
}
|
4. Parameter naming in methods
- The first character uses a lowercase letter.
- All characters after the first character are capitalized by the first character of the class naming convention.
- Such as:
12345 |
class EchoAnyWord{ function echoWord( $firstWord , $secondWord ){ ... } } |
5. Reference variables
- Reference variables are prefixed with the ' R ' prefix. Such as:
123456789 |
class
Example{
$mExam
=
""
;
funciton setExam(&
$rExam
){
...
}
function
getExam(){
...
}
}
|
6. Variable naming
- All letters are used in lowercase.
- Use ' _ ' 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 integer types; c,d,e,s they are generally used for character types.
- The instance variable is preceded by an underscore, the first lowercase letter, and 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
12 |
define( ‘DEFAULT_NUM_AVE‘ ,90); define( ‘DEFAULT_NUM_SUM‘ ,500); |
9. Static variables
- Static variables should be prefixed with ' s '. Such as:
10. Function naming
- All names use lowercase letters, and multiple words are split with ' _ '. Such as:
123 |
function this_good_idear(){ ... } |
The various naming conventions above can be combined together to use, such as:
123 |
class OtherExample{ $msValue = "" ; //该参数既是类属性,又是静态变量 } |
PHP Naming conventions