Home >Backend Development >PHP Tutorial >PDP Document Code Comment Specification Page 1/2_PHP Tutorial

PDP Document Code Comment Specification Page 1/2_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:48:03916browse

1. What is phpDocumentor?
PHPDocumentor is a tool written in PHP. For PHP programs with standard annotations, it can quickly generate API documents with cross-reference, indexing and other functions. The old version is phpdoc. Starting from 1.3.0, it has been renamed phpDocumentor. The new version adds support for php5 syntax. At the same time, documents can be generated by operating on the client browser, and the documents can be converted to PDF, HTML, There are several forms of CHM, which are very convenient.
When PHPDocumentor works, it will scan the PHP source code under the specified directory, scan the keywords, intercept the comments that need to be analyzed, then analyze the special tags in the comments, generate an xml file, and then based on the analyzed classes and Module information, establish corresponding indexes, generate xml files, and use customized templates to output files in the specified format for the generated xml files.
2. Install phpDocumentor
Like other modules under pear, the installation of phpDocumentor is also divided into automatic installation and manual installation. Both methods are very convenient:
a . Automatically install through pear
Enter at the command line
pear install PhpDocumentor
b. Manual installation
Download the latest version of PhpDocumentor (now 1.4.0) at http://manual.phpdoc.org/ and unzip the content.
3. How to use PhpDocumentor to generate documents
Command line method:
In the directory where phpDocumentor is located, enter
Php –h
and you will get a detailed parameter list. Several important parameters are as follows:
-f File names to be analyzed, multiple files separated by commas
-d Directory to be analyzed, multiple directories separated by commas
-t Storage path of the generated documents
- o The output document format, the structure is output format: converter name: template directory.
For example: phpdoc -o HTML:frames:earthli -f test.php -t docs
Web interface generation
In the new phpdoc, in addition to generating documents on the command line, you can also generate documents on the client To generate documents by operating on the browser, the specific method is to first place the content of PhpDocumentor in the apache directory so that it can be accessed through the browser. After access, the following interface is displayed:
Click the files button and select the php file or files to be processed. folder, you can also ignore the processing of certain files by specifying Files to ignore under this interface.
Then click the output button to select the storage path and format of the generated document.
Finally click create, and phpdocumentor will automatically start generating the document. The progress and status of the generation will be displayed at the bottom. If successful, it will be displayed
Total Documentation Time: 1 seconds
done
Operation Completed!!
Then, we can view the generated document. If it is in pdf format, the name defaults to documentation.pdf.
4. Add standardized comments to PHP code
PHPDocument generates documents from the comments of your source code, so the process of commenting on your program is also the process of compiling documentation.
From this point of view, PHPdoc encourages you to develop good programming habits and try to use specifications and clear text to annotate your program. At the same time, it more or less avoids the asynchronous development of documents and document updates afterwards. Some questions.
In phpdocumentor, comments are divided into documentation comments and non-documentation comments.
The so-called documentation comments are multi-line comments placed in front of specific keywords. Specific keywords refer to keywords that can be analyzed by phpdoc, such as class, var, etc. For details, please refer to Appendix 1.
Comments that do not precede keywords or are not standardized are called non-documentation comments. These comments will not be analyzed by phpdoc and will not appear in the API document you generate.
3.2 How to write documentation comments:
All documentation comments are a multi-line comment starting with /**, which is called DocBlock in phpDocumentor. DocBlock refers to a key comment written by a software developer. The help information of the keyword allows others to know the specific purpose of this keyword and how to use it. PhpDocumentor stipulates that a DocBlock contains the following information:
1. Function brief description area
2. Detailed description area
3. Mark tag
The first line of the documentation comment is the function description area, and the text is generally Briefly describe the function of this class, method or function. The text of the brief function description will be displayed in the index area in the generated document. The content of the function description area can be ended by a blank line or.
After the function description area is a blank line, followed by a detailed description area. This part is mainly to describe the function and purpose of your API in detail, if possible , you can also give examples of usage, etc. In this section, you should focus on clarifying the general purpose and usage of your API functions or methods, and indicate whether it is cross-platform (if involved). For platform-related information, you should treat it differently from general information. , the usual approach is to start a new line, and then write the precautions or special information on a specific platform. This information should be enough so that your readers can write corresponding test information, such as boundary conditions, parameter ranges, Breakpoints, etc.After
there is also a blank line, and then the document tag, indicating some technical information, mainly the call parameter type, return value and type, inheritance relationship, related methods/functions, etc.
Regarding document tags, please refer to Section 4: Document Tags for details.
You can also use tags such as in document comments. Please refer to Appendix 2 for details.
The following is an example of a documentation comment

Copy the code The code is as follows:

/**
* Function add, implements the addition of two numbers
*
* A simple addition calculation, the function accepts two numbers a and b, and returns their sum c
*
* @ param int addend
* @param int addend
* @return integer
*/
function Add($a, $b)
{
return $a+$b;
}

The generated document is as follows:
Add
integer Add( int $a, int $b)
[line 45]
Function add, to implement the addition of two numbers
Constants A simple For addition calculation, the function accepts two numbers a and b and returns their sum c
Parameters
• int $a - addend
• int $b - summand
5 . Document tags:
The scope of use of document tags refers to the keywords or other document tags that the tag can be used to modify.
All documentation tags begin with @ after * on each line. If the @ mark appears in the middle of a paragraph, the mark will be treated as normal content and ignored.
@access
Usage scope: class, function, var, define, module
This tag is used to indicate the access permission of keywords: private, public or protected
@author
Indicate the author
@copyright
Usage scope: class, function, var, define, module, use
Indicate copyright information
@deprecated
Usage scope: class, function, var, define, module, constent , global, include
Indicates unused or obsolete keywords
@example
This tag is used to parse a piece of file content and highlight them. Phpdoc will try to read the file content from the file path given by this tag
@const
Using scope: define
Used to indicate the constant of define in php
@final
Using scope: class ,function,var
indicates that the keyword is a final class, method, or attribute, and derivation and modification are prohibited.
@filesource
Similar to example, except that this tag will directly read the content of the currently parsed php file and display it.
@global
Indicates the global variable referenced in this function
@ingore
is used to ignore the specified keyword in the document
@license
is equivalent to < in the html tag ;a>, first the URL, then the content to be displayed
For example, Baidu
can be written as @license http ://www.baidu.com Baidu
@link
Similar to license
but you can also point to any keyword in the document through link
@name
Specify a keyword Alias.
@package
Usage scope: page level -> define, function, include
Class level ->class, var, methods
is used to logically combine one or several keywords Assigned to a group.
@abstrcut
Indicates that the current class is an abstract class
@param
Specifies the parameters of a function
@return
Specifies the return pointer of a method or function
@static
Indicates that the Guan Jianzi is static.
@var
Indicate the variable type
@version
Indicate the version information
@todo
Indicate areas that should be improved or not implemented
@throws
Indicate that this function may Error exceptions thrown, extremely rare
As mentioned above, ordinary document tags must be marked with @ at the beginning of each line. In addition, there is also a tag called inline tag, using {@} Expressions include the following types:
{@link}
Usage is the same as @link
{@source}
Display the content of a function or method
6. Some comment specifications
a. Comments must be in the form of
/**
* XXXXXXX
*/

b. For functions that reference global variables, glboal tags must be used.
c. For variables, their type must be marked with var (int, string, bool...)
d. The function must indicate its parameters and return value through param and return markers
e. For two occurrences For keywords used twice or more, the redundant ones should be ignored through ingore, and only one should be kept
f. Where other functions or classes are called, link or other tags should be used to link to the corresponding part to facilitate documentation. of reading.
g. Use non-documentation comments where necessary to improve code readability.
h. Keep descriptive content concise and to the point, using phrases rather than sentences whenever possible.
i. Global variables, static variables and constants must be declared with corresponding tags

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319862.htmlTechArticle1. What is phpDocumentor? PHPDocumentor is a tool written in PHP. For PHP programs with standard annotations, it Able to quickly generate API documents with cross-reference, indexing and other functions. Old...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn