PHP Variable naming recommendations

Source: Internet
Author: User
Tags php code

PHP is a weak type language, if there are many variables in the program, plus PHP many function names are very confusing, chaos on the confusion, see also dazzling.

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

I engaged in the development of PHP for many years, in order to lead the team more effective, and gradually formed a kind of PHP naming habits (behind a friend said is already existing Hungarian nomenclature), so that their procedures appear very clear.

I will give you the experience below, not necessarily for others, but still share.

String, literal, plus str in front of variable

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 variable, one-dimensional array using noun singular, multidimensional array use Word plural

Copy PHP content to clipboard

PHP Code:

//下面一个变量为一维数组
$aData = array ( 1 , 2 , 3 , 4 , 5 ,6) ;

//下面一个变量为多维数组
$aMembers = array ( 'id' => 123456 , 'username' => 'ABC' , 'email' => 'abc#abc.com' ) ;

Integer, integral type variable, preceded by ' n '

Copy PHP content to clipboard

PHP Code:

The following variable is an integer

$nCount = $pBS->member->getcount ();

Boolean, preceded by ' B '

Copy PHP content to clipboard

PHP Code:

One of the following variables is Boolean

$bEncode = true;

float, float, plus ' f ' in front

Copy PHP content to clipboard

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.