PHP code specifications analysis _ PHP Tutorial

Source: Internet
Author: User
PHP code specification analysis. I. writing Rule 1-indent. Use Tab (Tab key) indentation. the unit of indentation is 4 spaces. The length of a single line is controlled within 80 characters. if it is too long to start another line, it is in a reasonable position. I. writing rules

1-> indent. Use tabs ( Key) indent. the unit of indentation is 4 spaces. The length of a single line is controlled within 80 characters. if it is too long to start another line, it is disconnected at a reasonable position and indented by 8 characters to distinguish normal indentation.

2-> braces {}. Place braces in the same column (lower) of the keywords. You can use either of the following methods.


3-> Keywords, parentheses, functions, and operators. Parentheses and keywords are separated by a space. parentheses and functions must be pasted together to distinguish between keywords and functions. There must be a space between the operator and the variables or expressions on both sides (except for the character link operator.

($boo == ){                 

4-> when the code segment is large, the upper and lower lines should be added with blank lines. Only one blank line is used between the two code blocks, and multiple lines are prohibited.

5-> try not to use parentheses in the return statement. For example, return 1.

II. naming rules

1-> class name. The first character is capitalized, that is, the big camper name method. Such as Sample and BigClassObject.

2-> class property name. 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, mValue or mLongString.

3-> method name. The big hump method is adopted. Prefix Is best a verb, such as: Is, Get, Set, to describe the function of this method. For example, the parameter name in the GetNum, IsValue... method adopts the small camper name method.

4-> Variable/function naming. All letters are in lower case and the underscore _ is used as the boundary of each word. For example, $ msg_error and $ che_pwd. That is, the underline naming method.

5-> constant/global constant naming. All letters are in uppercase and the underscore _ is used as the word boundary.

For example: $ define ('default _ NUM_AVE ', 90 );

6-> Global variable: add the prefix "g", static variable: add the prefix "s", and reference variable: add the prefix "r ".

Indent 1-indent. Use Tab (Tab key) indentation. the unit of indentation is 4 spaces. The length of a single line is controlled within 80 characters. if the length is too long to start another line, it is in a reasonable position...

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.