We need to know some common sense in the study of development, such as variable naming rules is a very important habit, if you develop a good variable naming habits and you work with the team will be more receptive to you.
1. Class naming
(1) using the Camel name method (this is common in almost all languages)
(2) Minimum of 3 words
(3) Do not use uppercase letters in all abbreviations. Eg: use gethtmlstatic instead of gethtmlstatic.
2. Naming functions and methods
Usually each method and function performs an action, so naming them should clearly explain their purpose.
Eg: replace Errorcheck () with checkforerrors () and replace datafile () with Dumpdatatofile.
3. Class attribute naming
Attribute naming should be prefixed with the character "M". The prefix "M" is followed by a rule with a consistent class naming.
Eg:var MVar;
4. Variable naming
Make all the variables look different in the code and easily recognizable.
Local variable naming: All letters are lowercase, using "_" as the demarcation of each word
Eg: $time _of_error
Global variable naming: prefixed with "G"
Eg:global $gLog;
Static variable name: prefixed with "s"
Eg:static $msStatics = 0;
Name of reference variable: prefixed with "R"
Eg:var Mrstatus;
String, strings, preceded by a variable str
| The code is as follows |
Copy Code |
The following variable is a string type $strMessage = Hello world!; arrays, array type, plus a in front of variables, one-dimensional arrays using nouns singular, multidimensional arrays using word plural The following variable is a one-dimensional array $aData = Array (1, 2, 3, 4, 5, 6); The following variable is a multidimensional array $aMembers = Array (id = = 123456, username = ABC, emai L = abc#abc.com); integer, int variable, preceded by n The following variable is an integer $nCount = $pBS->member->getcount (); Boolean, with the Boolean type preceded by B The following variable is a Boolean type $bEncode = true; float, float, plus f in front
The following variable is a floating-point type $fSave = 0.8; 80 percent Pointer types, such as classes. Add P in front
The following is an instantiation of a class $pBP = new Bluepage; Resource, resource type, plus RS in front
$rsConn = mysql_connect (localhost, user, PW); $rsHandle = fopen ($strFilename); |
Unspecified variables, using MX
| The code is as follows |
Copy Code |
$mxData = GetData (); |
Custom functions, starting with fn_
| The code is as follows |
Copy Code |
function Fn_halterror ($strErrorMessage) { Do sth ... }
|
A comprehensive example (using a paging Class):
| The code is as follows |
Copy Code |
Include ("lib/bluepage.class.php"); $pBP = new Bluepage; $rsConn = mysql_connect (localhost, root, 123456) or D IE (mysql_error ()); mysql_select_db (test, $rsConn); $strQuery = "Select COUNT (' ID ') from test"; $nCount = $pBP->mygetcount ($strQuery, $rsConn); Total achieved if ($nCount < 1) { Fn_halterror ($aMessages [NoData]); } $nShowNum = 10; Pagination Group and HTML $aPDatas = $pBP->get ($nCount, $nShowNum); $strHtml = $pBP->gethtml ($aPDatas); The paging data contains offset, which takes the data $strQuery = "SELECT * FROM Test LIMIT". $aPDatas [OFFSE T]. ", " . $nShowNum; $rsResult = mysql_query ($strQuery); |
http://www.bkjia.com/PHPjc/632701.html www.bkjia.com true http://www.bkjia.com/PHPjc/632701.html techarticle in the development of learning we need to know some common sense, such as variable naming rules is a very important habit, if you develop a good variable naming habits and you work with the team will be more ...