Summary of the PHPDocument code comment specification

  • 2020-06-19 10:01:25
  • OfStack

1. phpDocumentor installation (command line installation is not recommended)
In http: / / manual. phpdoc. org PhpDoc/download the latest version
Put it in the web server directory and make it accessible through the browser
Click the files button to select the php file or folder to process
You can also omit processing of certain files by specifying Files to ignore under this interface.
Then click the output button to select the location and format of the generated document.
Finally, click create and phpdocumentor will automatically start generating documents.

2. How to write PHP specification comments
All document tags begin with an @ after each 1 line *. If the @ sign appears in the middle of a paragraph, it will be ignored as normal content.
@ access access permissions of this tag is used to identify key words: private, public or proteced use scope: class, function, var, define, module
author identifies the author
@copyright indicates copyright information
const range: define is used to specify define constants in php
class,function,var specifies that the keyword is a final class, method, attribute, and does not allow derivation or modification.
@global specifies the global variable referenced in this function
name specifies 1 individual name for the keyword.
@package is used to logically group one or more keywords into groups.
abstrcut indicates that the current class is an abstract class
@param specifies the parameters of a function
return specifies the return value of a method or function
static indicates that the custom build is static.
@ES65en specifies the variable type
version specifies version information
todo indicates areas that should be improved or not implemented
@link can point to any 1 keyword in the document via link
ingore is used to ignore specified keywords in a document

Some annotation specifications
a. Comments must be
/**
* XXXXXXX
*/
In the form of
b. For functions that reference global variables, the glboal flag must be used.
For variables, the type must be labeled with var (int,string,bool...)
d. The function must indicate its arguments and return values through the param and return tags
e. For keywords that appear twice or more, ignore the redundant ones through 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 documentation.
g. Use non-documentation comments (comments before keywords that PHPDOC does not recognize) where necessary to improve code readability.
Keep descriptive content as brief as possible, using phrases rather than sentences when possible.
i. Global variables, static variables, and constants must be labeled accordingly

Keywords that can be recognized by phpdoc:
Include
Require
include_once
require_once
define
function
global
class

3. php code for standard annotations:
< ?php
/**
* File name (sample2.php)
*
* Function description (omitted)
*
* @author steve < https://www.ofstack.com >
* @version 1.0
* @package sample2
*/
/**
* Include files
*/
include_once 'sample3.php';
/**
* Declare global variables
* @global integer $GLOBALS['_myvar']
* @name $_myvar
*/
$GLOBALS['_myvar'] = 6;
/**
* Declare global constants
*/
define('NUM', 6);
/**
* the name of the class
*
* Class function description
*
* @package sample2
* @subpackage classes(add if parent)
*/
class myclass {
/**
* Declare ordinary variables
*
* @accessprivate
* @var integer|string
*/
var $firstvar = 6;
/**
* Create constructor {@link $firstvar}
*/
function myclass() {
$this- > firstvar = 7;
}
/**
* Defined function
*
* Function description
*
* @global string $_myvar
* @staticvar integer $staticvar
* @param string $param1
* @param string $param2
* @return integer|string
*/
function firstFunc($param1, $param2 = 'optional') {
static $staticvar = 7;
global $_myvar;
return $staticvar;
}
}
? >


Related articles: