Name ====================================
Class naming
The first letter of the first name uses uppercase
Capitalize the first letter of each word, use lowercase for all other letters
Do not use underscores _ for example:
Class Nameonetwo
Class Name
Method naming
First letter lowercase, use the word first letter uppercase or underline _ link each word, underline _ after the word first letter lowercase
Class Nameonetwo {
function Doit_note () {};
function HandleError () {};
}
Class Property naming
Attribute naming should be prefixed with the character M.
The prefix m is followed by a rule with a consistent class naming.
The prefix ' m ' prevents any conflicts between class properties and method names. Method names and property names are often very similar, especially for accessing elements.
For example
Class Nameonetwo {
var Merrornumber;
var mrname;
function Varabc () {};
}
Class static variables
Static variables should be prefixed with s
For example
Class Nameonetwo {
static $msStatus = 0;
}
Variable naming
Rule and method naming
Global constants
Global constants All letters should be capitalized and delimited by _
For example
Define ("A_global_constant", "Hello world!");
Folder file name
Folder naming is generally used in English, the length is generally not more than 15 characters, named in lowercase letters. Some common folder names are: Images or img (storing graphics files), Flash (storing flash files), style or CSS (storing CSS files), scripts or JS (storing JavaScript scripts), media (storing multimedia files), etc.
File names are combined in lowercase letters, numbers, and underscores.
Comment ====================================
Comments should be accurate and understandable, preventing comments from being two semantic. Wrong comments are not only useless but harmful
The comment of the block is often used/*...*/, the line comment is generally used//...
All PHP code source files should have a C language-style comment at the beginning, listing the class name, feature, version information, date, author
/*
* function
* Date
* Author
* Version
* Copyright
*/
For example
/**
* Agent Management Center Module
* @date 2015.5.22
* @author Zhang XXX
* @since v2.0
* @copyright Copyright (c) 2013-2015 a technology
*/
method annotations such as
/**
* User Center Right, small navigation (function)
*
* @param string $menu _type navigation type
* @param string $menu _key the current navigation Menu_key
* @param array $array additional menu
* @return Array $arrUser
*/
If time is pressing at least to specify the method, for example
/**
* CMS Feature Editor
*/
If the file has been modified, you should indicate the purpose of the modification, modify the date, modify the person, and identify the beginning and end of the modified section before the corresponding code.
......
/*
* Purpose of modification
* Date Modified
* Modify People
* Version
*/
......
Modify a person to modify the start
......
......
Modified Person Modification End
......
Initialization of variables ====================================
Try to declare a local variable while initializing it. The only reason for not doing this is that the initial value of the variable depends on some previously occurring calculation.
Layout ====================================
Separated by a blank line between methods and methods
Unify a tab character as a unit of indented typography.
Separated by a space between the operator and the variable
In multiple parameter lists (methods, or arrays), there should be a space after the parameter comma
The numeric constants that are used as counter values in the For loop, except for -1,0 and 1, should not be written directly to the code.
Curly braces {} are used
For, if, when, do, switch, and so on after the keyword {want to walk with the keyword
For example
if (true) {
......
}
The code block within {} is left-aligned at the bottom indent one tab. Do not allow spaces instead of tab
Auto-formatting indent in editor set to tab
Positioning of the Declaration block
The variable is declared only at the beginning of the code block. (a block is any code that is contained in the middle of the curly braces "{" and "}".) Do not declare when the variable is first used.
Multiple variables are "categorized" according to the order in which the system executes the call. When assigning values to multiple variables, the equals sign after the same category is aligned with a space control
For example
function MyMethod () {
The beginning of the method block
$name = $_get[' name '];
$age = $_get[' age '];
$sex = $_get[' sex '];
$model 1 = Model ();
$model 2 = Model ();
$int 1 = 0;
$int 2 = 0;
if ($condition) {
int $int 2 = 0; The start of the "if" block
...
}
}
PHP code blocks are marked with <?php?>. Forbidden to use <??> or <?=?>
Parentheses, keywords, and function space rules
After the keyword is blank, you cannot discriminate the keyword. Do not put parentheses and if, for, and while and other keywords close together, to separate them with a space to highlight the keyword
The parentheses following the method name should be followed by the method name, and no spaces will be left
If, for, when, do, and so on the statement from the row, the execution statement must not follow immediately thereafter. Add {} No matter how many statements are executed. This will prevent writing mistakes.
Switch format, all case-aligned one indent under switch, and all case corresponding execution statement in one indent
If a case branch is executed and continues to proceed to the next cases execution, a comment must be written
Line length
Try to avoid a line that is longer than 80 characters because many terminals and tools cannot handle it well.
Line break
When an expression cannot fit within a line, it can be broken according to the following general rules:
-Break after a comma
-Break in front of an operator
-The new line should be aligned with the beginning of the same level expression on the previous line
-If the above rules result in code clutter or if the code is stacked on the right, then indent a tab character instead
PHP Coding Specification