PHP coding specification comments and file structure descriptions

Source: Internet
Author: User

File structure

|-Images
|-Include
|-Parameter
|-Config
| -- Function
| -- Index
Images Stores image files. Include is a file to be referenced by the system. It generally stores parameter files in parameter, config stores configuration files, and function stores method files, for example, Javascript methods, and the classes of each function are also classified by functional modules.
File Name
Folder names are generally in English and generally contain no more than 20 characters. Chinese Pinyin is used only in special cases. Some common folder names include: images (storing graphic files), flash (storing Flash files), and style (storing CSS files ), scripts (storing JavaScript scripts), Inc (storing include files), Link (storing links), and media (storing multimedia files. The file name must contain lowercase letters, numbers, and underscores.
Block comment
Block annotations are usually used to provide information about files, methods, data structures, and Algorithm . Block annotations are placed at the beginning of each file and before each method. They can also be used in other places, such as internal methods. Block comments within functions and methods should be included inCode It has the same indent format.
There should be a blank line at the beginning of the block comment to separate the block comment from the code, for example:
/*
* Here is the block comment.
*/
The block annotation can start with/*-, so that indent (1) can recognize it as the beginning of a code block without shuffling it.
/*-
* If you want to be ignored, block annotations in special format are used.
*
* One
* Two
* Three
*/
Note: if you do not use indent (1), you do not need to use/*-in the Code, or make concessions for others to run indent (1) on your code.
Single line comment
A short comment can be displayed in a row and has the same indentation level as the subsequent code. If a comment cannot be written in a row, block comment should be used. There should be a blank line before a single line comment. The following is an example of a single line comment in the Code:
If (condition ){
/* Conditions for running the following code */
...
}
End comment
Very short comments can be in the same line as the code they want to describe, but there should be enough white space to separate the code and comments. If multiple short comments appear in a large code segment, they should have the same indentation.
The following is an example of the end comment in the Code: Copy code The Code is as follows: if ($ A = 2 ){
Return true;/* description of a single condition */
} Else {
Return isprime ($ A);/* Other conditions */
}

End comment
The annotator "//". You can comment out a part of the entire line or a row. It is generally not used for comments of multiple consecutive rows; however, it can be used to comment out code segments of multiple consecutive rows. The following are examples of all three styles:Copy codeThe Code is as follows: if ($ Foo> 1 ){
// Second usage.
...
}
Else {
Return false; // The reason for the returned value
}
// If ($ bar> 1 ){
//
/// Method 3
//...
//}
// Else {
// Return false;
//}

Document comment
This document describes PHP classes, constructors, methods, and fields ). Each document annotation is placed in the annotation separator/**... */, and a comment corresponds to a class or member. The comment should be prior to the Declaration:

/**
* Describes some of the classes...
*/
Class Example {...

Note that the top-level class is not indented, and its members are indented. The first line (/**) of the document comment of the description class does not need to be indented; the subsequent document comment lines are indented by 1 (vertical alignment of the asterisks ). Member, including the constructor, the first line of the comments in the document is Indented by 4 cells, and then each line is Indented by 5 cells.
If you want to provide information about classes, variables, or methods that are not suitable for writing in the document, you can use implementation block annotations (see 5.1.1) or a single line comment that follows the declaration (see 5.1.2 ). For example, the implementation details of a class should be placed in the implementation block comment followed by the class declaration, rather than in the document comment.
Document comments cannot be placed in the definition block of a method or constructor, becauseProgramThe first statement after the document comment is associated with it.

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.