PDP Document Code Comment specification

Source: Internet
Author: User
1. What is Phpdocumentor?
Phpdocumentor is a tool written in PHP that can quickly generate cross-references for PHP programs with canonical annotations. IndexAPI documentation for other functions. The old version is Phpdoc, starting from 1.3.0, renamed Phpdocumentor, the new version adds support for PHP5 syntax, and can be converted to pdf,html,chm in several forms by manipulating the document on the client browser.
When the phpdocumentor is working, it scans the PHP source code under the specified directory, scans the keywords, intercepts the comments that need to be analyzed, then parses the dedicated tag in the note, generates the XML file, and then builds the corresponding data based on the classes and modules that have been parsed. Index, generates an XML file for the generated XML file, using a custom template to output the file in the specified format.
2. Installing Phpdocumentor
As with other pear modules, the installation of Phpdocumentor is also divided into automatic installation and manual installation of two ways, both of which are very convenient:
A Automatic installation via Pear
At the command line, enter
Pear Install Phpdocumentor
b Manual Installation
Download the latest version of Phpdocumentor (now 1.4.0) in http://manual.phpdoc.org/and unzip the content.
3. How to use Phpdocumentor to generate documents
Command line mode:
In the directory where the Phpdocumentor is located, enter
Php–h
A detailed parameter table is given, and several important parameters are as follows:
-F file name to parse, multiple files separated by commas
-D directories to parse, multiple directories separated by commas
-t the stored path of the generated document
-O Output document format, structure output format: Converter name: Template directory.
Example: Phpdoc-o html:frames:earthli-f test.php-t Docs
Web Interface Generation
In the new Phpdoc, in addition to the command line to generate documents, you can also operate on the client browser to generate documents, the method is to first put the contents of Phpdocumentor in the Apache directory so that the browser can access to, after access to display the following interface:
Click the Files button to select the php file or folder you want to work with, and you can ignore the processing of some files by specifying file to ignore under that interface.
Then click the Output button to select the path and format of the generated document.
Finally click Create,phpdocumentor will automatically start to generate the document, the bottom will show the progress and status of the build, if successful, will show
Total documentation time:1 seconds
Done
Operation completed!!
Then we can view the generated document, and if it is in PDF format, the name defaults to Documentation.pdf.
4. Add a specification comment to the PHP code
Phpdocument is a document generated from the comments in your source code, so the process of commenting on your program is the process of documenting it.
From this point, Phpdoc urges you to develop good programming habits, as far as possible to use specifications, clear text for your program to make comments, but also more or less to avoid the post-mortem document and document updates are not synchronized some problems.
In Phpdocumentor, comments are divided into document comments and non-document comments.
The so-called document comments, are those placed in front of a particular keyword, the multi-line comment, the specific keyword refers to be able to be phpdoc analysis of keywords, such as Class,var, specific can participate in Appendix 1.
Comments that are not preceded by a keyword or are not canonical are referred to as non-document comments that will not be parsed by Phpdoc and will not appear in the API text you produce.
3.2 How to write a document comment:
All of the documentation comments are a multiline comment starting with/**, called DocBlock in Phpdocumentor, and DocBlock is a software developer's help on a keyword that allows others to know what the keyword is for and how to use it. Phpdocumentor Specifies that a DocBlock contains the following information:
1. Function Summary Area
2. Detailed Description Area
3. Mark Tag
The first line of the document comment is the function description area, which is usually a concise description of the function of the class, method, or function, and the body of the function summary will appear in the generated document IndexArea. The contents of the function description area can be either a blank line or a. To end
After the function description area is a blank line, followed by the detailed description area. This part of the main is to explain the functionality of your API, use, if possible, there can be examples of usage and so on. In this section, you should focus on the usual use of your API functions or methods, use them, and indicate whether they are cross-platform (if involved), for information about the peace table, you are going to be treated differently from the general information, usually by a different line, and then write out on a particular platform Precautionsor special information, this information should be sufficient so that your readers can write the appropriate test information, such as boundary conditions, parameter ranges, breakpoints, and so on.
After that is also a blank line, then the document tag tag, indicating some technical information, mainly the most important is the call parameter type, return value is extremely type, inheritance relationship, related methods/functions and so on.
For more information on document tagging, refer to section Fourth: Document tagging.
The documentation comments can also be used for example Please refer to Appendix Two for a detailed description of this label.
Here is an example of a document comment
/**
* Function add to achieve two number of additions
*
* A simple addition calculation, the function accepts two numbers A, B, returns their and C
*
* @param int Addend
* @param int Summand
* @return Integer
*/
function Add ($a, $b)
{
return $a + $b;
}
The resulting document is as follows:
Add
Integer ADD (int $a, int $b)
[Line 45]
function Add, implement two number of additions
Constants A simple addition calculation, the function accepts two numbers A, B, returns their and C
Parameters
? int $a-Addend
? int $b-Summand
5. Document Tags:
The use of a document tag is a keyword, or other document tag, that the tag can be used to decorate.
All document tags begin with a * after each line. If the mark of @ is out of the middle of a paragraph, the tag will be ignored as normal content.
@access
Scope of Use: Class,function,var,define,module
The tag is used to indicate access rights for the keyword: private, public, or proteced
@author
Specify the author
@copyright
Scope of Use: Class,function,var,define,module,use
Specify copyright information
@deprecated
Scope of Use: Class,function,var,define,module,constent,global,include
Identify unused or deprecated keywords
@example
This tag is used to parse the contents of a file and highlight them. Phpdoc will attempt to get from this token to the file pathRead FileContent
@const
Scope of Use: Define
Constants used to indicate define in PHP
@final
Scope of Use: Class,function,var
Indicates that the keyword is a final class, method, property, prohibit derivation, modification.
@filesource
Similar to example, except that the tag directly reads and displays the contents of the currently parsed PHP file.
@global
That indicates the reference in this function.Global Variables
@ingore
Used to omit the specified keyword from the document
@license
Equivalent to the HTML tag, first the URL, followed by the content to be displayed
For exampleBaidu
Can write @license http://www.baidu.comBaidu
@link
Similar to license
But you can also refer to any one of the keywords in the document by using link
@name
Specifies an alias for the keyword.
@package
Scope of Use: page-level, define,function,include
Class-Level->class,var,methods
Used to logically divide one or several keywords into a group.
@abstrcut
Indicates that the current class is an abstract class
@param
Indicates the parameters of a function
@return
Indicates that the return of a method or function refers to the
@static
Indicates that the off-build word is static.
@var
Indicate variable type
@version
Specifying version information
@todo
Identify areas that should be improved or not implemented
@throws
Indicates that this function may throw an error exception, which can occur in extreme cases
As mentioned above, ordinary document tag tags must be at the beginning of each line at the @ mark, in addition, there is a tag called inline tag, with {@}, including the following:
{@link}
Usage with @link
{@source}
Show the contents of a function or method
6. Some annotation specifications
A. The comment must be
/**
* XXXXXXX
*/
The form
B. For references to theGlobal Variablesfunction, you must use the glboal tag.
C. For variables, the type must be marked with VAR (int,string,bool ... )
D. Functions must indicate their arguments and return values through the Param and return tags
E. For keywords that appear two or more times or more than two times, you need to ignore the excess by ingore and keep only one
F. Where other functions or classes are called, use link or other tags to link to the appropriate section for easy document reading.
G. Use non-document annotations where necessary to improve code legibility.
H. Descriptive content as concise as possible, using phrases rather than sentences.
I.Global VariablesStatic Variablesand constants must be indicated by corresponding tags
7. Summary
Phpdocumentor is a very powerful document auto-generation tool that helps us write specification annotations, generate easy-to-understand, well-structured documents, and can help with our code upgrades, maintenance, handover, and more.
For more detailed instructions on phpdocumentor, you can go to its official website
http://manual.phpdoc.org/Check
8. Appendix
Appendix 1:
Keywords that can be identified by Phpdoc:
include
require
include_once
require_once
Define
function
Global
Class
Appendix 2
Tags that can be used in a document










    • Appendix III:
      A piece of PHP code that contains specification comments
      /**
      * Sample File 2, Phpdocumentor Quickstart
      *
      * This file demonstrates the rich information so can be includeD in
      * In-code documentation through Docblocks and tags.
      * @author Greg Beaver
      * @version 1.0
      * @package Sample
      */
      Sample file #1
      /**
      * Dummy includeValue, to demonstrate the parsing power of Phpdocumentor
      */
      include_once ' sample3.php ';
      /**
      * Special global variable Declaration DocBlock
      * @global integer $GLOBALS [' _myvar ']
      * @name $_myvar
      */
      $GLOBALS [' _myvar '] = 6;
      /**
      * Constants
      */
      /**
      * First constant
      */
      Define (' testing ', 6);
      /**
      * Second constant
      */
      Define (' Anotherconstant ', strlen (' Hello '));
      /**
      * A Sample Function DocBlock
      * @global String Document The fact that this function uses $_myvar
      * @staticvar integer $staticvar This is actually what's returned
      * @param string $param 1 name to declare
      * @param string $param 2 value of the the name
      * @return Integer
      */
      function Firstfunc ($param 1, $param 2 = ' optional ')
      {
      static $staticvar = 7;
      Global $_myvar;
      return $staticvar;
      }
      /**
      * The first example class, this was in the same package as the
      * Procedural stuff in the start of the file
      * @package Sample
      * @subpackage Classes
      */
      class MyClass {
      /**
      * A Sample Private variable, this can is hidden with the--parseprivate
      * option
      * @access Private
      * @var integer|string
      */
      var $firstvar = 6;
      /**
      * @link http://www.example.com Example link
      * @see MyClass ()
      * @uses testing, Anotherconstant
      * @var Array
      */
      var $secondvar =
      Array
      ' Stuff ' =
      Array
      6,
      17,
      ' Armadillo '
      ),
      testing = Anotherconstant
      );
      /**
      * Constructor sets up {@link $firstvar}
      */
      function MyClass ()
      {
      $this->firstvar = 7;
      }
      /**
      * Return a thingie based on $paramie
      * @param boolean $paramie
      * @return Integer|babyclass
      */
      function Parentfunc ($paramie)
      {
      if ($paramie) {
      return 6;
      } else {
      return new Babyclass;
      }
      }
      }
      /**
      * @package Sample1
      */
      Class Babyclass extends MyClass {
      /**
      * The answer to life, the Universe and everything
      * @var Integer
      */
      var $secondvar = 42;
      /**
      * Configuration Values
      * @var Array
      */
      var $thirdvar;
      /**
      * Calls Parent constructor, then increments {@link $firstvar}
      */
      function Babyclass ()
      {
      Parent::myclass ();
      $this->firstvar++;
      }
      /**
      * This is always returns a MyClass
      * @param ignored $paramie
      * @return MyClass
      */
      function Parentfunc ($paramie)
      {
      return new MyClass;
      }
      }
      ?>

      The above describes the PDP document code annotation specification, including the require,include, global variables, notes, Baidu content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.