首页
开发手册
应用中心
工具
用户中心
FoundPHP Development Naming Convention
English
中文简体
English
上一篇
下一篇
### FoundPHP Development Naming Convention FoundPHP development is the same as traditional PHP. The author takes into account the similarity between the rules in development and the traditional PHP, and proposes the following specifications. It is recommended that it is more convenient to follow this specification. Here are the naming methods: variables, functions, classes。 #### 1. Variable Naming - Variables are all composed of lowercase words and can be abbreviated. Such as: $us, $img, $ary, etc. - Use'_' as a delimiter for each word. Such as: $msg_error, $us_pwd, etc. - Temporary variables are usually named `i, j, k, m, and n`, and they are generally used for integer types. ------------ #### 2. Function Naming - Function names are all lowercase words or pinyin multiple words use _ as the delimiter. Such as: font_cut(), user_check(), etc. - It is necessary to write a comment for function writing. It is recommended to use `/* comment content */` so that multiple lines of comments can be used to explain how to use the function. - The function value is less than or equal to 3 groups of parameters directly assigned to avoid errors due to unassigned values. ```PHP /* user_id userid user_name user_name user_age user_age */ function user_info($user_id=0,$user_name='',$user_age=18){ //processing content echo $user_id.',名字: '.$user_name.' age: '.$user_age; } //instructions user_info(1,'tonsen',22); ``` - More complex functions need to deal with a variety of data, but when the data is not fixed, you can use the array form. ```PHP /* ary user_id userid user_name user_name user_age user_age */ function user_info($ary=array()){ //processing content echo $ary['user_id'].',name: '.$ary['user_name'].' age: '.$ary['user_age']; } //use method user_info(array( 'user_id' =>1, 'user_name' =>'tonsen', 'user_age' =>22, )); ``` ------------ #### 3. Class/Method Naming - Use uppercase and lowercase letters for words or pinyin for multiple words, use _ as a delimiter. Such as: FoundPHP_img, FoundPHP_user, etc. - Class attribute naming is the same as variable usage ```PHP class FoundPHP_img{ var $img_width = 88; //class attribute var $img_height = 88; //class attribute } ``` - Class method naming is the same as function naming. ```PHP class FoundPHP_img{ /* max_width maximum width value */ function set_width($max_width=300){ //method processing } } ``` ------------ FoundPHP adopts a relatively uniform naming rule, which is convenient for developers to reduce learning costs and improve code readability. During the development process, Chinese users try to use English words as much as possible, and please avoid using pinyin or pinyin abbreviations for naming.