每一个PHPer都应当掌握的注释标记

简介

注释标签在代码注释中的做用很是大,可是可能不少同窗在日常开发中会忽略这些标签的做用,因此我这边特意整理一些经常使用的注释标记,经过图文展示形式,但愿能帮助你能更好理解每一个注释标签的做用.php

或许你离漂亮的代码,就差一个标签^_^git

项目工程地址 : https://github.com/yinggaozhen/doc-demo/tree/master/phpgithub

_segmentfault

@deprecated

@deprecated : 被此标记的函数或者成员方法表示下个版本将会被废弃,告知适用方再也不推荐使用此方法.数组

详细代码演示 : https://github.com/yinggaozhen/doc-demo/tree/master/php/deprecatedsvg

语法

@deprecated [<version>] [<description>]

描述

  • @deprecated能够填写一个版本号,版本号的规则同@version
  • 若是被标记的方法只是由于被其余新方法代替而被废弃,能够结合@see来表示被代替的方法

标签效果

demo.jpg

_函数

@inheritdoc

@inheritdoc : 文档继承,会继承父类的文档注释.单元测试

详细代码演示 : https://github.com/yinggaozhen/doc-demo/tree/master/php/inheritdoc测试

语法

@inheritDoc

描述

  • @inheritDoc会继承父类的全部文档注释.在继承以后能够对指定字段进行重写

标签效果

1.直接继承

demo1.jpg

2.继承重写

demo2.jpg

_this

@internal

@internal : 被此标签标记的内部类/方法,做用范围只能限于当前文件,外部文件不可调用.

详细代码演示 : https://github.com/yinggaozhen/doc-demo/tree/master/php/internal

语法

@internal [description]

使用场景

此标签一般可以使用在单元测试中,好比在单元测试中定义了一个测试用的类,可对此测试类添加@internal标签,这样别人在正常逻辑中万一不当心错误引用了测试类,在IDE的帮助下,能够第一时间获得反馈.

标签效果

demo.jpg

_

@link

@link : 此标签能够引导你到指定的外部跳转连接.

详细代码演示 : https://github.com/yinggaozhen/doc-demo/tree/master/php/link

语法

@link [URI] [<description>]

描述

该标签只有1个跳转选项

和@see的区别

- @see @link
外部连接
内部程序 X

_

@see

@see : 此标签能够引导你到指定的外部跳转连接/内部程序.

详细代码演示 : https://github.com/yinggaozhen/doc-demo/tree/master/php/see

语法

@see [URI | FQSEN] [<description>]

描述

该标签能够有两个跳转选项

  • @外部跳转连接 : 必须是知足RFC2396的跳转连接,例如http://github.com/yinggaozhen
  • @内部程序连接 : 能够跳转到制定的类/方法/变量,如class::method

和@link的区别

- @see @link
外部连接
内部程序 X

_

@var

@var : 定义一个数据的类型.

详细代码演示 : https://github.com/yinggaozhen/doc-demo/tree/master/php/var

语法

@var [Type] [$element_name] [<description>]

变量列表

变量类型 说明
string 字符串
integer/int number/int类型
boolean/bool false/true
float/double number/浮点数
object 对象实例
specifiedType 指定类
mixed 任意类型
array/specifiedType[] 数组,能够指定成指定类型的数组
resource 文件资源类型
void 无返回值
null -
callable 可执行的回调函数
function 不必定能执行的方法
self/$this 当前实例

标签效果

实现@var能够有两种使用方法

1.在类成员变量中定义,不须要指定变量名称

demo.jpg

2.直接给具体变量定义,须要指定变量名称

demo.jpg

_

@throws

@throws : 抛出一个异常,告诉调用方须要作好处理异常相关工做.

详细代码演示 : https://github.com/yinggaozhen/doc-demo/tree/master/php/throws

语法

@throws [Type] [<description>]

标签效果

demo.jpg

_

最后

文章篇幅有限,这里列举了一部分标签,更多标签能够经过如下工程地址

项目工程地址 : https://github.com/yinggaozhen/doc-demo/tree/master/php

标签会不按期持续更新,欢迎各位star & fork

您的支持是我更新的最大动力~~

相关文章
相关标签/搜索