Home > Article > Backend Development > PHP specific analysis on naming rules
As far as general conventions are concerned, the names of classes, functions, and variables should be such that code readers can easily know the function of these codes, and ambiguous naming should be avoided.
1. Class naming
Use uppercase letters to separate words, and use lowercase letters for other letters.
Use capital letters for the first letter of the name.
Do not use underscore ('_').
Such as: Name, SuperMan, BigClassObject.
2. Class attribute naming
The attribute naming should be prefixed with the character ‘m’.
The prefix ‘m’ follows the same rules as class naming.
‘m’ always modifies the beginning of a name, just like ‘r’ represents a reference.
Such as: mValue, mLongString, etc.
##3. Naming of methods
class StartStudy{ //设置类 $mLessonOne = ""; //设置类属性 $mLessonTwo = ""; //设置类属性 function getLessonOne(){ //定义方法,得到属性mLessonOne的值 ... } }
4. Name the parameters in the method
##
class EchoAnyWord{ function echoWord($firstWord,$secondWord){ ... } }
class Example{ $mExam = ""; funciton setExam(&$rExam){ ... } function getExam(){ ... } }
##Constants and global constants should all be in uppercase letters between words. Use '_' to separate. Such as
define('DEFAULT_NUM_AVE',90); define('DEFAULT_NUM_SUM',500);
9. Static variables
Static variables should have Prefix 's'. For example:
state $sStatus = 1;
10. Function naming
All names are Use lowercase letters and use '_' to separate multiple words. For example:
function this_good_idear(){ ... }
The various naming rules above can be used in combination, such as:
class OtherExample{ $msValue = ""; //该参数既是类属性,又是静态变量 }
The above is the detailed content of PHP specific analysis on naming rules. For more information, please follow other related articles on the PHP Chinese website!