Understand the source file encoding standards of PHP coding standards

Source: Internet
Author: User
Tags coding standards php coding standards
Understand the source file encoding specifications for PHP coding specifications <STRONG> <FONTsize = 4> start comments </FONT> </STRONG> <P> all source files must start with one notes on C style, lists the class names and functions. Start comments

All source files should start with a C-language style comment, which lists the class name, function, version information, date, author, and copyright statement:


/*
* Class name
* Efficacy
* Version
* Date
* Author
* Copyright
*/

If the document has been modified, the document header should be used to clarify the object, date, author, and version information of the document. if part of the document is corrected, then, you can annotate the file and identify the starting and ending position of the corrected part.

......

/*
* Rectification target
* Correction date
* Author
* Version
*/

......

Correction start

......

......

Rectification ended

......

3.2 import statements

The import statement should be in the file header and clarify the role of the import file during the import. For example:

// Database control class
Require ("db. php ");

Declaration of the 3.3 class

Annotation of class 1 Documents (/**...... */) The information to be included in the comment. For more information, see 'document annotation'
Class 2 declaration
Annotations for the three types of implementations (/*...... */) If necessary, the comment should contain any information about all classes, which is not suitable for commenting class documents.
Class 4 (static) variables are first the public variables of the class, followed by the protection variables, followed by the package-level variables (without visiting the modifier, access modifier), and finally private variables.
5. the instance variables are at the public level first, followed by the protection level, followed by the package level (no visit modifier), and finally the private level.
6 constructors
7 methods these methods should be grouped according to the efficacy, rather than the scope or access permissions. For example, a private class method can be placed between two public instance methods. Its goal is to make it easier to browse and understand code.

3.4 indent layout

Four spaces are often used as a unit of indentation. The description of indentation is not specified (space vs. tab ). A single tab is eight spaces (not four), so in some compilers, you need to specify the length of the tab to 4 (UltraEdit), and in some compilers, converts a tab to a space.

3.5 rows in length

Avoid a row containing more than 80 characters, because many terminals and tools do not have much interest.

3.6 line feed

When an expression cannot be contained in a row, it can be disconnected according to the following general rules:

-Disconnected after a comma
-Disconnected before a controller
-Select a higher-level disconnection, rather than a lower-level disconnection.
-The new row should be aligned with the beginning of the expression of the previous row at the same level.
-If the above rules cause disorder in your code or make your code pile up on the right side, you should indent it with eight spaces.

The following are examples of method call disconnection:


SomeMethod (longExpression1, longExpression2, longExpression3,

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.