I wrote this today to remind myself that the programming process is not only logical, but also code readable.
Thanks for the documentation provided by the Ox God
1, PHP programming norms and coding habits of the main points are the following:
1 Document Description
2 Function Body Description
3 Code Indentation
4 if omitted
5 Variable Specification
6 Naming conventions
70 Line One note
8 Annotation Style
9 Open Close principle
2. Document description Personal code-specifications are as follows:
1<?2 /*3 +----------------------------------------------------------------------4 + Title: Title5 + Author: Author6 + Version: Revision number7 + Initial-time: The time this file was initially created8 + Last-time: The last modified time of this file + the name of the modified person9 + Desc: A simple description of this fileTen +---------------------------------------------------------------------- One */
3. Function Body Description:
1<?2 /**3 * Simple description of function body4 * @author_start: Author5 * @author_end: Modified time + Modified by6 * @param string: $id description7 * @param array: $array description8 * @param array: $num description9 * @return: Return value DescriptionTen */ One functionTest ($id,$array=Array(),$num= 1){ A}
Note: The code indentation style of the variable parameter inside the function
4, Code indentation:
1<?2 $str= 1;3 $info= ' 123 ';4 $version= ' 123123 ';5 $name= ' Test ';6 $i= ' haha ';7 8 #generally at the most external if or process control statements should be left and left blank line9 if($info) {Ten One } A - #generally the most external for or foreach should be left and left blank line - for($i=0,$i<6,$i++){ the -}
5. If omitted
1<?2 #in the case where the exit or return is present in the Process Control statement of the IF statement and its branch, it should omit some of its else operations3 #Error4 if () {5 return false;6}Else {7 return true;8 }9 #correctTen if () { One return false; A } - return true;
6, variable specification, the use of English name
1 <? 2 # correct 3 $title = ' title ' 5 $pwd = ' password ' 6 # error 7 $biaoti = ' title ' 9 $mima = ' password ';
7. Naming specification
1<?2 /**3 * In the actual development, there are three kinds of naming methods in general.4 * Note: No matter the class name, variable, method name, in real development, can only be a combination of no more than 3 words5 * Big hump: Capitalize each word first letter6 * Small hump: Middle Word first Letter capital7 * Serpentine: Each word is lowercase, the word is used with the word _ link8 */9 Ten #Large hump, commonly used for class name definitions One classcar{} A classbluecar{} - - #Small hump, commonly used for method name definitions the classcar{ - Public functionGetColor () {} - } - + #serpentine, commonly used for variable name definitions - $res _id= 1; + $res _name= 2;
9. Annotation Style
1<?21, use the following annotation style when you need to do a lot of describing a piece of code3 /**4 * I'm a description5 *① Process One6 *② Process Two7 *③ Process Three8 */9 Ten2, use the following annotation style when you need to make a small description of a line of code One #This is the XXXX to zzzz variable, called CCCC A $name= ' '; - -3, use the following annotation style when you need to do a description of a line of code the $name= ";//fields of the X table - $index _head= ";//Home Request Header
10. Open Closure principle
This is actually a concept, one of the design patterns.
In short, it is a class or API that has been completed on-line and can be extended externally without altering the original file.
PHP Programming Specification