PHP variable naming suggestions. PHP is a weak language. if there are many variables in the program, and many functions in PHP are named in disorder, they will be dazzled. Unified coding style and even change
PHP is a weak language. if there are many variables in the program, and many functions in PHP are named in disorder, they will be dazzled.
Uniform coding style and even variable naming are very important in team development.
I have been engaged in PHP development for many years. in order to make the team more efficient, I gradually formed a naming convention for PHP (some friends later said it was an existing Hungarian naming convention ), make your program look very clear.
Next I will share my experience with you. it may not be applicable to others, but I will share it with you.
String, string type, add str before the variable
Copy the PHP content to the clipboard.
PHP code:
// The following variable is of the string type.
$ StrMessage = Hello World! ;
Array: array type. add a to the variable. one-dimensional arrays use singular nouns and multidimensional arrays use the plural words.
Copy the PHP content to the clipboard.
PHP code:
// The following variable is a one-dimensional array.
$ AData = array (1, 2, 3, 4, 5, 6 );
// The following variable is a multi-dimensional array.
$ AMembers = array (id => 123456, username => ABC, email => abc # abc.com );
Integer, an integer variable, plus n
Copy the PHP content to the clipboard.
PHP code:
// The following variable is an integer.
$ NCount = $ pBS-> Member-> getCount ();
Boolean: The boolean type is preceded by B.
Copy the PHP content to the clipboard.
PHP code:
// The following variable is Boolean.
$ BEncode = true;
Float, float type, plus f
Copy the PHP content to the clipboard.
PHP code:
// The following variable is floating point
$ FSave = 0.8; // off
Pointer type, such as class. Add p
Copy the PHP content to the clipboard.
PHP code:
// The following is the instantiation of a class
$ PBP = new BluePage;
Resource, resource type. add rs to the front
Copy the PHP content to the clipboard.
PHP code:
$ RsConn = mysql_connect (localhost, user, pw );
$ RsHandle = fopen ($ strFilename );
Unknown variable, using mx
Copy the PHP content to the clipboard.
PHP code:
$ MxData = getData ();
User-defined function, starting with fn _
Copy the PHP content to the clipboard.
PHP code:
Function fn_HaltError ($ strErrorMessage)
{
// Do something...
}
A comprehensive example (using paging classes ):
Copy the PHP content to the clipboard.
PHP code:
Include ("lib/BluePage. class. php ");
$ PBP = new BluePage;
$ RsConn = maid (localhost, root, 123456) or die (mysql_error ());
Mysql_select_db (test, $ rsConn );
$ StrQuery = "select count ('id') FROM test ";
$ NCount = $ pBP-> myGetCount ($ strQuery, $ rsConn); // obtain the total number
If ($ nCount <1)
{
Fn_HaltError ($ aMessages [nodata]);
}
$ NShowNum = 10;
// Pagination array and html
$ APDatas = $ pBP-> get ($ nCount, $ nShowNum );
$ StrHtml = $ pBP-> getHTML ($ aPDatas );
// The page data contains offset, and the data is retrieved.
$ StrQuery = "SELECT * FROM test LIMIT". $ aPDatas [offset]. ",". $ nShowNum;
$ RsResult = mysql_query ($ strQuery );
Bytes. Unified coding style, and even changed...