PHP naming rules ____php

Source: Internet
Author: User

In terms of general conventions, the names of classes, functions, and variables should be able to make it easy for code readers to know the role of the code, and should avoid the use of the name of the Ling ambiguous.

1. Class naming

Use uppercase letters as the segmentation of a word, and all other letters use lowercase.
The first letter of a first name is capitalized.
Do not use underline ('_').
such as: Name, Superman, Bigclassobject.

2. Class attribute naming

Attribute names should be prefixed with the character ' M '.
The prefix ' m ' is followed by a rule that is consistent with the class name.
' m ' always modifies the beginning of the name, as if it were a reference at the beginning of ' R '.
such as: Mvalue, mlongstring, etc.

3. Nomenclature of methods

The function of a method is to perform an action to achieve a goal. So the name should show what the method is. The prefix for a generic name has a first rule, such as is (judgment), get (obtained), set (set).
method to name the first letter in lowercase, and then capitalize the initial letter of the word. Such as:

Class startstudy{//Setting classes
$mLessonOne = ""; Set class properties
$mLessonTwo = ""; Set class properties
function Getlessonone () {//define method, get property Mlessonone value
...
}
}

4. Parameter naming in method

The first character uses a lowercase letter.
All characters after the first character are capitalized according to the first character of the class naming rule.
Such as:

Class echoanyword{
function Echoword ($firstWord, $secondWord) {
...
}
}

5. Reference variables

Reference variables are prefixed with the ' R ' prefix. Such as:


Class example{
$mExam = "";
Funciton Setexam (& $rExam) {
...
}
function Getexam () {
...
}
}

6. Variable naming

All letters use lowercase.
Use ' _ ' as the dividing line for each word.
such as: $msg _error, $chk _pwd and so on.
Temporary variables are usually named I,j,k,m and N, and they are generally used for integers; c,d,e,s They are generally used for character types.
The instance variable requires an underscore, the first lowercase, and the remainder of the first letter of the word.

7. Global variables

Global variables should be prefixed with ' G '. such as: Global $gTest.

8. Constants, Global constants

constants, global constants, all uppercase letters should be used, and words should be separated by ' _ '. Such as

Define (' Default_num_ave ', 90);
Define (' Default_num_sum ', 500);

9. Static variables

The static variable should be prefixed with ' s '. Such as:

state $sStatus = 1;

10. Function naming

All names use lowercase letters, and multiple words are split using ' _ '. Such as:


function This_good_idear () {
...
}



The various naming conventions above can be combined together to use, such as:

Class otherexample{
$msValue = ""; This parameter is both a class attribute and a static variable
}

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.