PHP variable naming recommendations _php tutorial

Source: Internet
Author: User

PHP is a weak type of language, if there are many variables in the program, plus PHP Many of the functions of the name are very chaotic, chaotic, and see the dazzling.

Unified coding style, even variable naming, is very important in team development.

I have been engaged in the development of PHP for many years, in order to make the team more effective, and gradually formed a PHP naming habit (after a friend said that there is already a Hungarian nomenclature), so that their procedures look very clear.

Below I will give you experience, not necessarily apply to others, but still share.

String, strings, preceded by a variable str
Copy PHP content to clipboard
PHP 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
Copy PHP content to clipboard
PHP Code:
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, email = abc#abc.com);


integer, int variable, preceded by n
Copy PHP content to clipboard
PHP Code:
The following variable is an integer
$nCount = $pBS->member->getcount ();


Boolean, with the Boolean type preceded by B
Copy PHP content to clipboard
PHP Code:
The following variable is a Boolean type
$bEncode = true;


float, float, plus f in front
Copy PHP content to clipboard
PHP Code:
The following variable is a floating-point type
$fSave = 0.8; 80 percent


Pointer types, such as classes. Add P in front
Copy PHP content to clipboard
PHP Code:
The following is an instantiation of a class
$pBP = new Bluepage;


Resource, resource type, plus RS in front
Copy PHP content to clipboard
PHP Code:
$rsConn = mysql_connect (localhost, user, PW);

$rsHandle = fopen ($strFilename);


Unspecified variables, using MX
Copy PHP content to clipboard
PHP Code:
$mxData = GetData ();


Custom functions, starting with fn_
Copy PHP content to clipboard
PHP Code:
function Fn_halterror ($strErrorMessage)
{
Do sth ...
}


A comprehensive example (using a paging Class):
Copy PHP content to clipboard
PHP Code:
Include ("lib/bluepage.class.php");
$pBP = new Bluepage;

$rsConn = mysql_connect (localhost, root, 123456) or Die (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 [offset]. ", " . $nShowNum;
$rsResult = mysql_query ($strQuery);

http://www.bkjia.com/PHPjc/508293.html www.bkjia.com true http://www.bkjia.com/PHPjc/508293.html techarticle PHP is a weak type of language, if there are many variables in the program, plus PHP Many of the functions of the name are very chaotic, chaotic, and see the dazzling. Unified coding style, even change ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.