PHP Development and writing specifications

Source: Internet
Author: User
N {} extension line feed principle: The Beginning bracket and the keyword are in the same direction, and the ending bracket and the keyword are in the same column. There is a space between the square brackets and the previous content.

The most basic PHP writing specifications are summarized as follows:

N {} extension line feed principle: The Beginning bracket and the keyword are in the same direction, and the ending bracket and the keyword are in the same column. There is a space between the beginning bracket and the previous content.

 

The sample code is as follows:

Function get_clientip (){


If ($ _ SERVER ["HTTP_X_FORWARDED_FOR"]) {

$ Ip = $ _ SERVER ["HTTP_X_FORWARDED_FOR"];

} Elseif ($ _ SERVER ["HTTP_CLIENT_IP"]) {

$ Ip = $ _ SERVER ["HTTP_CLIENT_IP"];

} Else {

$ Ip = false;

}

Return $ ip;

}

 

In the n if structure, if and elseif are in the same direction with the two parentheses. even if there is only one statement after if, braces must be added to ensure the structure is clear.

N indent layout principle:

All indentions replace tabs with spaces. The PHP file uses four spaces for indentation. the HTML file and the Javascript code embedded in the HTML file use two spaces for indentation. the separate Javascript and CSS files use four spaces for indentation. Every developer involved in the project needs to set it forcibly in the editor (UltraEdit, EditPlus, Zend Studio, etc.) to prevent the code being forgotten and resulting in format irregularities.

N leave a blank line before the comment so that the comment can be clearly seen. the comment is usually followed by the following code;

N All PHP and HTML files are saved as the character encoding of the No Bom UTF-8;

N annotation writing: according to the popular annotation writing method, we need to write the annotation of the code segment in the following way:

/* Comment */

For single line comments, use the following comments. Note that there is a space after //, for example:

Define ('in _ ECS', ture); // comment the content.

N =,>, <运算符需要左右各空一格;< p>

N other operators, such as +,-, and %, can be left-side without spaces or right-side spaces for ease of reading;

N methods and methods, even if there is no comment, a row is required. It is best to write a comment for each method;

N. each side has a space;

N private variable. the private method should preferably start with _ (underline );

It is better to leave a blank line before the return statement.

Related Article

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.