Home Backend Development PHP Tutorial PHPDocument 代码注释规范总结

PHPDocument 代码注释规范总结

Jun 20, 2016 pm 01:02 PM
php comments

 

PHPDocument 代码注释规范

1. 安装phpDocumentor(不推荐命令行安装)
在http://manual.phpdoc.org/下载最新版本的PhpDoc
放在web服务器目录下使得通过浏览器可以访问到
点击files按钮,选择要处理的php文件或文件夹
还可以通过该指定该界面下的Files to ignore来忽略对某些文件的处理。
然后点击output按钮来选择生成文档的存放路径和格式.
最后点击create,phpdocumentor就会自动开始生成文档了。

2.如何写PHP规范注释

所有的文档标记都是在每一行的 * 后面以@开头。如果在一段话的中间出来@的标记,这个标记将会被当做普通内容而被忽略掉。

@access 该标记用于指明关键字的存取权限:private、public或proteced 使用范围:class,function,var,define,module
@author 指明作者
@copyright 指明版权信息
@const 使用范围:define 用来指明php中define的常量
@final 使用范围:class,function,var 指明关键字是一个最终的类、方法、属性,禁止派生、修改。
@global 指明在此函数中引用的全局变量
@name 为关键字指定一个别名。
@package 用于逻辑上将一个或几个关键字分到一组。
@abstrcut 说明当前类是一个抽象类
@param 指明一个函数的参数
@return 指明一个方法或函数的返回值
@static 指明关建字是静态的。
@var 指明变量类型
@version 指明版本信息
@todo 指明应该改进或没有实现的地方
@link 可以通过link指到文档中的任何一个关键字
@ingore 用于在文档中忽略指定的关键字

一些注释规范
a.注释必须是

/**
* XXXXXXX
*/
Copy after login


的形式
b.对于引用了全局变量的函数,必须使用glboal标记。
c.对于变量,必须用var标记其类型(int,string,bool…)
d.函数必须通过param和return标记指明其参数和返回值
e.对于出现两次或两次以上的关键字,要通过ingore忽略掉多余的,只保留一个即可
f.调用了其他函数或类的地方,要使用link或其他标记链接到相应的部分,便于文档的阅读。
g.必要的地方使用非文档性注释(PHPDOC无法识别的关键字前的注释),提高代码易读性。
h.描述性内容尽量简明扼要,尽可能使用短语而非句子。
i.全局变量,静态变量和常量必须用相应标记说明

能够被phpdoc识别的关键字:
Include
Require
include_once
require_once
define
function
global
class

3. 规范注释的php代码 :


/**
* 文件名(sample2.php)
*
* 功能描述(略)
* 
* @author steve 
* @version 1.0
* @package sample2
*/

/**
* 包含文件
*/
include_once 'sample3.php';

/**
* 声明全局变量
* @global integer $GLOBALS['_myvar']
* @name $_myvar
*/
$GLOBALS['_myvar'] = 6;

/**
* 声明全局常量
*/
define('NUM', 6);

/**
* 类名
* 
* 类功能描述
*
* @package sample2
* @subpackage classes(如果是父类 就添加)
*/
class myclass {

/**
* 声明普通变量
* 
* @accessprivate
* @var integer|string
*/
var $firstvar = 6;

/**
* 创建构造函数 {@link $firstvar}
*/
function myclass() {
$this->firstvar = 7;
}

/**
* 定义函数
*
* 函数功能描述
* 
* @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;
}
}
Copy after login


Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP comments revealed: detailed comparison of single-line comments and multi-line comments PHP comments revealed: detailed comparison of single-line comments and multi-line comments Mar 15, 2024 pm 12:51 PM

The Secret of PHP Comments: Detailed Comparison of Single-line Comments and Multi-line Comments PHP is a widely used web development language, in which the use of comments plays a vital role in the readability and maintainability of the code. In PHP, common comments come in two forms: single-line comments and multi-line comments. This article will compare these two annotation forms in detail and provide specific code examples to help readers better understand their usage and differences. 1. Single-line comments A single-line comment is to add a line of comments in the code, starting with // and going to the end of the line. Single line comments

What are the types of php comments? What are the types of php comments? Aug 23, 2023 pm 01:46 PM

The types of PHP comments include single-line comments, multi-line comments, document comments, conditional comments, etc. Detailed introduction: 1. A single line comment starts with a double slash "//" and is used to comment a single line of code. In this comment type, everything from the beginning of the double slash to the end of the line will be regarded as a comment, not Will be interpreted as code; 2. Multi-line comments start with a slash asterisk "/" and end with an asterisk slash "*/". This comment type can be used to comment a piece of code or multiple lines of code; 3. Documentation comments It also starts with a slash-asterisk "/", ends with an asterisk-slash "*/", and so on.

Code comments in PHP Code comments in PHP May 23, 2023 am 08:27 AM

Code comments are text reminders that programmers add when writing code to make it easier for themselves and other programmers to read and understand the code. In PHP, code comments are indispensable. This article will introduce in detail the types, specifications and uses of code comments in PHP. 1. Code comment types in PHP In PHP, there are three types of comments: single-line comments, multi-line comments and documentation comments. Single-line comments A single-line comment starts with a double slash "//" and ends at the end of the line. For example: //This is a single line comment multi-line comment multi-line comment ends with "

Detailed explanation of PHP comment types: single-line comments and multi-line comments Detailed explanation of PHP comment types: single-line comments and multi-line comments Mar 15, 2024 pm 05:27 PM

PHP is a popular server-side scripting language widely used in the field of web development. In the code writing process, comments are a very important element, which can help developers better understand the code and improve the readability and maintainability of the code. This article will introduce the comment types in PHP in detail, including single-line comments and multi-line comments, and provide specific code examples. Single-line comments In PHP, single-line comments can be achieved by using double slashes //. Single-line comments start with // and continue to the end of the line. Single-line comments are often used to comment on code

A closer look at PHP comments: the difference between single-line and multi-line comments A closer look at PHP comments: the difference between single-line and multi-line comments Mar 15, 2024 pm 05:15 PM

When entering the field of PHP programming, comments are a very important concept. When writing code, comments are crucial to clarify the intent of the code, help other developers understand the code logic, and facilitate yourself to maintain the code in the future. In PHP, comments are divided into single-line comments and multi-line comments, and there are some differences in usage. This article will deeply explore the characteristics of PHP comments and the use of single-line comments and multi-line comments, and illustrate it through specific code examples. 1. Single-line comments A single-line comment is to add a line of comments to the code to explain

What are the types of comments in php What are the types of comments in php Jul 25, 2023 pm 02:26 PM

The types of comments in PHP are: 1. Single-line comments, used to explain a certain function, remind other developers or yourself to pay attention, etc.; 2. Multi-line comments, used to explain multi-line code blocks in detail; 3. Document comments , used to provide a detailed description of the entire code block or function or method.

PHP Comment Specification: How to use documentation comments to write API documentation PHP Comment Specification: How to use documentation comments to write API documentation Jul 30, 2023 pm 07:00 PM

PHP Comment Specification: How to use documentation comments to write API documentation Introduction: When developing PHP applications, writing complete API documentation is very important for the development team and other developers. Good documentation improves code readability and maintainability, and promotes teamwork and information sharing. This article will introduce how to use documentation comments to write PHP API documentation, and provide some sample code to help readers understand how to write comments in a standardized way. Comment specification In PHP, we use comments to explain and describe the code. generally

How to use comments in PHP to enhance code readability and understandability How to use comments in PHP to enhance code readability and understandability Jul 15, 2023 pm 09:27 PM

How to use comments in PHP to enhance code readability and understandability Introduction: During the development process, comments are a very important component that can help developers better understand the code and improve the readability and maintainability of the code. . This article will introduce how to use comments in PHP to enhance the readability and understandability of code, and provide some practical code examples. Single-line comments Single-line comments are used to explain and illustrate a certain line of code. In PHP, single-line comments start with double slashes (//) and end at the end of the line. Here is an example

See all articles