The name of a variable
A) All letters use lowercase
b The first letter is specified according to the variable value type
I. Integer i
Ii. floating-point number F
Iii. string S
Iv. Boolean value B
V. Array A
Vi. object o
Vii. Resources R
Viii. Mixed Type M
C Use ' _ ' as a dividing line for each word
For example:
$i _age_max = 10;
$f _price = 22.5;
$s _name = ' Harry ';
$b _flag = true;
$a _price = Array ();
$o _object = new Class ();
$r _file = fopen ();
$m _var = array_combine ($a _name, $a _flag);
Second, class naming
A the use of uppercase letters as a separate word, the other letters are in lowercase, that is, the hump format.
b The first letter of the first name uses uppercase
c) Do not use the underline ('_')
d) The interface interface is best to use the uppercase letter I and end with interface
For example:
Class Nameonetwo
Class Name
Interface Iexampleinterface ()
Third, the method name
A the use of uppercase letters as a separate word, and all other letters using lowercase
b The first letter of the name is capitalized, declared as "private" or "protected", using ' _ ' as the prefix
c) Do not use the underline ('_')
d) (rules consistent with class naming)
E The accessors of an object are always prefixed with "get" or "set", and when a design pattern such as a single state mode (singleton) or a factory pattern (factory) is used, the method's name should contain the name of the pattern, so that it is easy to identify the design pattern from the name.
For example:
Class nameonetwo{
Public Function DoIt () {};
Protect function _handleerror () {};
Private Function _sayhello () {};
}
Four, class attribute naming
A the attribute name prefix should be specified as a property value type (specific reference variable naming rule)
b prefix followed by a rule that is consistent with the class name
c The private attribute is prefixed with ' _ '
For example:
Class Nameonetwo {
Public Function Varabc () {};
Public Function ErrorNumber () {};
Public $iAge;
Private $_iage;
}
Name of the parameter in the method
A) reference class attribute naming
For example:
Class Nameonetwo {
Public Function Varabc ($SMSG) {};
}
Six, global variables
A the global variable should be prefixed with ' g '
b The rest of the reference variable naming rules
For example:
Global $gi _age;
Global $ga _price
Vii. defining named/Global constants
A global constant uses ' _ ' to split each word
b) all letters using uppercase
For example:
Define (' E_error_missing_para ', 501);
Eight, function
A) All letters in lowercase, using ' _ ' to separate each word
For example:
function Some_bloody_function () {
}
Nine, curly braces {} rules
(a) Place the curly braces at the same column or peer below the keyword, recommended to the peer
For example:
function Some_bloody_function () {
}
if (true) {
Code
}
Ten, Indent/tab rules
A) using tab indents
For example:
function Some_bloody_function () {
if (true) {
Code
}
}