Php naming rules

Source: Internet
Author: User
Php naming rules

  1. Class NameOneTwo
  2. Class Name

2. class library naming

Currently, namespaces are becoming more and more widely used to avoid class name conflicts between different vendors and group class libraries. When namespace is not used, to avoid class name conflicts, the general practice is to add a unique prefix before the class name, the two characters can be used, of course, it will be better to use more. For example:

  1. John Johnson's data structure class library can use Jj as the prefix, as shown below:
  2. Class JjLinkList
  3. {
  4. }

3. method naming

The same rule as the class naming rule also serves to interpret the method using English words. For example:

  1. Class NameOneTwo
  2. {
  3. Function DoIt (){};
  4. Function HandleError (){};
  5. }

4. class attribute naming

The attribute name should be prefixed with the character'm. The prefix 'M' follows the same class naming rule. 'M' always acts as a modifier at the beginning of the name, just like a reference starting with 'R. The prefix 'M' prevents any conflicts between class attributes and method names. Your method name and attribute name are often very similar, especially for accessing elements. For example:

  1. Class NameOneTwo
  2. {
  3. Function VarAbc (){};
  4. Function ErrorNumber (){};
  5. Var mVarAbc;
  6. Var mErrorNumber;
  7. Var mrName;
  8. }

5. name parameters in the method

The first character uses lowercase letters. All words after the first character are capitalized according to the class naming rules. In this way, you can know which variable corresponds to which variable at any time. In addition, you can use a name similar to the class name without duplicate name conflicts. For example:

  1. Class NameOneTwo
  2. {
  3. Function StartYourEngines (
  4. & $ RSomeEngine,
  5. & $ RAnotherEngine );
  6. }

6. variable naming

All letters are in lower case. Use '_' as the boundary of each word. In many php tutorials, I have done this. In this way, the scope of variables in the code is clear. All variables look different in the code and are easy to identify. For example:

  1. Function HandleError ($ errorNumber)
  2. {
  3. $ Error = OsErr ();
  4. $ Time_of_error = OsErr-> getTimeOfError;
  5. $ Error_processor = OsErr-> getErrorProcessor;
  6. }

7. global variable naming

The global variable must have the prefix 'G '. It is very important to know the scope of a variable. For example:

  1. Global $ gLog;
  2. Global & $ grLog;

8. function naming

The function name follows the c gnu convention. all letters use lowercase letters and '_' to separate words. This makes it easier to distinguish the names of associated classes. For example:

  1. Function some_bloody_function ()
  2. {
  3. }

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.