目录
PHPDocumentor 注释规范整理
你会写注释么?从我写代码开始,这个问题就一直困扰着我,相信也同样困扰着其他同学。以前的写注释总是没有一套行之有效的标准,给维护和协同开发带了许多麻烦,直到最近读到了phpdocumentor的注释标准。
 
下面对phpdocumentor的注释标准进行总结:
首页 后端开发 php教程 PHPDocumentor 注释规范整理_PHP教程

PHPDocumentor 注释规范整理_PHP教程

Jul 13, 2016 am 10:21 AM
注释

PHPDocumentor 注释规范整理

你会写注释么?从我写代码开始,这个问题就一直困扰着我,相信也同样困扰着其他同学。以前的写注释总是没有一套行之有效的标准,给维护和协同开发带了许多麻烦,直到最近读到了phpdocumentor的注释标准。

 

下面对phpdocumentor的注释标准进行总结:


Type(数据类型):

 

    1. string 字符串类型
    2. integer or int 整型
    3. boolean or bool 布尔类型 true or false
    4. float or double 浮点类型
    5. object 对象
    6. mixed 混合类型 没有指定类型或不确定类型时使用
    7. array 数组
    8. resource 资源类型 (如数据库查询返回)
    9. void 空值(控制器返回值经常使用)
    10. null null类型
    11. callable 回调函数
    12. false or true 只返回true or fasle 时使用
    13. self 自身

       

      Tags(标签):

       

      Tag

      Element

      Description

      api

      Methods

      声明接口

      author

      Any

      作者信息

      category

      File, Class

      将一系列的元素分类在一起

      copyright

      Any

      版权信息

      deprecated

      Any

      声明元素已被弃用,可以在将来的版本中删除

      example

      Any

      示例

      filesource

      File

      文件资源

      global

      Variable

      声明一个全集变量

      ignore

      Any

      忽略当前元素 (phpdocumentor 生成文档时)

      internal

      Any

      声明一个值为整形,或者设置一个应用的默认值为整型

      license

      File, Class

      声明许可类型

      link

      Any

      声明一个和当前元素有关的链接

      method

      Class

      声明当前类那些魔术方法可以被调用

      package

      File, Class

      声明当前元素所属的包

      param

      Method, Function

      声明当前元素的一个参数

      property

      Class

      声明当前类有那些魔术方法可以被调用属性

      property-read

      Class

      声明当前类有那些魔术方法可以读取属性

      property-write

      Class

      声明当前类有那些魔术方法可以设置属性

      return

      Method, Function

      返回值

      see

      Any

      说明当前元素参数引用于其他站点或元素

      since

      Any

      声明当前元素始于于哪个版本

      source

      Any, except File

      展示当前元素的源码

      subpackage

      File, Class

      将当期元素分类

      throws

      Method, Function

      说明当前元素抛出的异常

      todo

      Any

      说明当前元素的开发活动

      uses

      Any

      引用一个关联元素

      var

      Properties

      声明属性

      version

      Any

      版本

       

       

      Example(示例):

       

      // =============================

       

      @api

       

       

      /**
        * This method will not change until a major release.
        *
        * @api
        *
        * @return void
        */
        function showVersion()
        {
           <...>
        }
      登录后复制

      // =============================

      @author

      /**
        * @author My Name
        * @author My Name <my.name@example.com>
        */</my.name@example.com>
      登录后复制

      // =============================

      @category

       /**
        * Page-Level DocBlock
        *
        * @category MyCategory
        * @package  MyPackage
        */
      登录后复制

      // =============================

      @copyright

      /**
        * @copyright 1997-2005 The PHP Group
        */
      登录后复制

      // =============================

      @deprecated

      /**
        * @deprecated
        * @deprecated 1.0.0
        * @deprecated No longer used by internal code and not recommended.
        * @deprecated 1.0.0 No longer used by internal code and not recommended.
        */
       function count()
       {
           <...>
       }
      登录后复制

      // =============================

      @example

      /**
        * @example example1.php Counting in action.
        * @example http://example.com/example2.phps Counting in action by a 3rd party.
        * @example My Own Example.php My counting.
        */
       function count()
       {
           <...>
       }
      登录后复制

      // =============================

      @filesource

      /**
        * @filesource
        */
      登录后复制

      // =============================

      @global phpdocumentor2.0不支持

      // =============================

      @ignore

      if ($ostest) {
           /**
            * This define will either be &#39;Unix&#39; or &#39;Windows&#39;
            */
           define(OS,Unix);
       } else {
           /**
            * @ignore
            */
           define(OS,Windows);
       }
      登录后复制

      // =============================

      @internal

       /**
        * @internal
        *
        * @return integer Indicates the number of items.
        */
       function count()
       {
           <...>
       }
      登录后复制

       /**
        * Counts the number of Foo.
        *
        * {@internal Silently adds one extra Foo to compensate for lack of Foo }}
        *
        * @return integer Indicates the number of items.
        */
       function count()
       {
           <...>
       }
      登录后复制

      // =============================

      @license

      /**
        * @license GPL
        * @license http://opensource.org/licenses/gpl-license.php GNU Public License
        */
      登录后复制

      // =============================

      @link

      /**
        * @link http://example.com/my/bar Documentation of Foo.
        *
        * @return integer Indicates the number of items.
        */
       function count()
       {
           <...>
       }
      登录后复制

      /**
        * This method counts the occurrences of Foo.
        *
        * When no more Foo ({@link http://example.com/my/bar}) are given this
        * function will add one as there must always be one Foo.
        *
        * @return integer Indicates the number of items.
        */
       function count()
       {
           <...>
       }
      登录后复制

      // =============================

      @method

      class Parent
       {
           public function __call()
           {
               <...>
           }
       }
       
       /**
        * @method string getString()
        * @method void setInteger(integer $integer)
        * @method setString(integer $integer)
        */
       class Child extends Parent
       {
           <...>
       }
      登录后复制

      // =============================

      @package

      /**
        * @package PSRDocumentationAPI
        */
      登录后复制

      // =============================

      @param

      /**
        * Counts the number of items in the provided array.
        *
        * @param mixed[] $items Array structure to count the elements of.
        *
        * @return int Returns the number of elements.
        */
       function count(array $items)
       {
           <...>
       }
      登录后复制

      // =============================

      @property

      class Parent
       {
           public function __get()
           {
               <...>
           }
       }
       
       /**
        * @property string $myProperty
        */
       class Child extends Parent
       {
           <...>
       }
      登录后复制

      // =============================

      @property-read

      class Parent
       {
           public function __get()
           {
               <...>
           }
       }
       
       /**
        * @property-read string $myProperty
        */
       class Child extends Parent
       {
           <...>
       }
      登录后复制

      // =============================

      @property-write

       class Parent
       {
           public function __set()
           {
               <...>
           }
       }
       
       /**
        * @property-write string $myProperty
        */
       class Child extends Parent
       {
           <...>
       }
      登录后复制

      // =============================

      @return

      /**
        * @return integer Indicates the number of items.
        */
       function count()
       {
           <...>
       }
      登录后复制

      /**
        * @return string|null The label&#39;s text or null if none provided.
        */
       function getLabel()
       {
           <...>
       }
      登录后复制

      // =============================

      @see

       /**
        * @see http://example.com/my/bar Documentation of Foo.
        * @see MyClass::$items           for the property whose items are counted
        * @see MyClass::setItems()       to set the items for this collection.
        *
        * @return integer Indicates the number of items.
        */
       function count()
       {
           <...>
       }
      登录后复制

      // =============================

      @since

      /**
        * @since 1.0.1 First time this was introduced.
        *
        * @return integer Indicates the number of items.
        */
       function count()
       {
           <...>
       }
      登录后复制

       /**
        * @since 1.0.2 Added the $b argument.
        * @since 1.0.1 Added the $a argument.
        * @since 1.0.0
        *
        * @return void
        */
       function dump($a, $b)
       {
           <...>
       }
      登录后复制

      // =============================

      @source

      /**
        * @source 2 1 Check that ensures lazy counting.
        */
       function count()
       {
           if (null === $this->count) {
               <...>
           }
       }
      登录后复制

      // =============================

      @subpackage

      /**
        * @package PSR
        * @subpackage DocumentationAPI
        */
      登录后复制

      // =============================

      @throws

      /**
        * Counts the number of items in the provided array.
        *
        * @param mixed[] $array Array structure to count the elements of.
        *
        * @throws InvalidArgumentException if the provided argument is not of type
        *     &#39;array&#39;.
        *
        * @return int Returns the number of elements.
        */
       function count($items)
       {
           <...>
       }
      登录后复制

      // =============================

      @todo

       /**
        * Counts the number of items in the provided array.
        *
        * @todo add an array parameter to count
        *
        * @return int Returns the number of elements.
        */
       function count()
       {
           <...>
       }
      登录后复制

      // =============================

      @uses

      /**
        * @uses MyClass::$items to retrieve the count from.
        *
        * @return integer Indicates the number of items.
        */
       function count()
       {
           <...>
       }
      登录后复制

      // =============================

      @var

       class Counter
       {
      /**
        * @var
        */
      public $var;
       }
      登录后复制

      // =============================

      @version

      /**
        * @version 1.0.1
        */
       class Counter
       {
           <...>
       }
      登录后复制

       /**
        * @version GIT: $Id$ In development. Very unstable.
        */
       class NeoCounter
       {
           <...>
       }
      登录后复制

       

       

       

       

       

       

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/857042.htmlTechArticlePHPDocumentor 注释规范整理 你会写注释么?从我写代码开始,这个问题就一直困扰着我,相信也同样困扰着其他同学。以前的写注释总是没有...
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

便捷使用PyCharm快捷键实现多行注释 便捷使用PyCharm快捷键实现多行注释 Jan 27, 2024 am 08:02 AM

PyCharm多行注释快捷键:让代码注释更加便捷,需要具体代码示例在日常的编程工作中,代码注释是非常重要的一部分。它不仅可以提高代码的可读性和可维护性,还能帮助其他开发人员理解代码的意图和设计思路。然而,手动添加代码注释往往是一项耗时而繁琐的工作。为了让我们的代码注释更加高效,PyCharm提供了多行注释的快捷键。在PyCharm中,我们可以使用Ctrl+/

如何优化Java代码的可维护性:经验与建议 如何优化Java代码的可维护性:经验与建议 Nov 22, 2023 pm 05:18 PM

如何优化Java代码的可维护性:经验与建议在软件开发过程中,编写具有良好可维护性的代码是至关重要的。可维护性意味着代码能够被轻松理解、修改和扩展,而不会引发意外的问题或额外的工作量。对于Java开发者来说,如何优化代码的可维护性是一个重要课题。本文将分享一些经验和建议,帮助Java开发者提升其代码的可维护性。遵循规范的命名规则规范的命名规则能够使代码更易读,

go语言中怎么注释多行 go语言中怎么注释多行 Jan 05, 2023 am 10:59 AM

在go语言中,可以使用多行注释符“/**/”来注释多行代码。多行注释(简称块注释),以“/*”开头,并以“*/”结尾,且不可以嵌套使用,语法“/*注释内容...*/”;多行注释一般用于包的文档描述或注释成块的代码片段。

如何在iPhone上为保存的密码添加注释 如何在iPhone上为保存的密码添加注释 Feb 28, 2024 pm 07:41 PM

iCloud钥匙串使您能够更方便地管理密码,无需依赖记忆或猜测网站或用户名。您可以通过在iCloud钥匙串中为应用程序和网站的现有密码添加注释来实现这一点。在这篇文章中,我们将解释如何为您保存在iPhone上的iCloud钥匙串中的密码添加注释。要求您需要满足一些要求才能在iCloud钥匙串中使用这项新功能。运行iOS15.4或更高版本的iPhone密码储存在iCloud钥匙串中的有效AppleID有效的互联网连接如何为保存的密码添加注释毋庸置疑,您应该在iCloudKeychain中存储一些密

PyCharm注释操作指南:优化代码编写体验 PyCharm注释操作指南:优化代码编写体验 Feb 21, 2024 pm 06:27 PM

PyCharm注释操作指南:优化代码编写体验在日常的代码编写中,注释是非常重要的一环。良好的注释不仅可以提高代码的可读性,还能帮助其他开发人员更好地理解和维护代码。PyCharm作为一款强大的Python集成开发环境,在注释方面也提供了丰富的功能和工具,可以极大地优化代码编写体验。本文将介绍如何在PyCharm中进行注释操作,以及如何利用PyCharm的注释

一文详解golang中的注释 一文详解golang中的注释 Mar 21, 2023 pm 07:38 PM

Golang是一种编程语言,它有着比较高的代码可读性和简洁性。然而,在编写代码时,总有些地方需要添加注释来帮助解释某些细节或者增加代码的可读性。在这篇文章中,我们将介绍一些关于Golang注释的内容。

分享PyCharm中快速注释代码的技巧,提高工作效率 分享PyCharm中快速注释代码的技巧,提高工作效率 Jan 04, 2024 pm 12:02 PM

效率提升!PyCharm中快速注释代码的方法分享在日常的软件开发工作中,我们经常需要注释掉一部分代码进行调试或者调整。如果手动逐行添加注释,这无疑会增加我们的工作量和耗费时间。而PyCharm作为一款强大的Python集成开发环境,提供了快速注释代码的功能,大大提升了我们的开发效率。本文将分享一些在PyCharm中快速注释代码的方法,并提供具体的代码示例。单

提升代码注释效率的神奇工具:让PyCharm成为您的首选 提升代码注释效率的神奇工具:让PyCharm成为您的首选 Jan 05, 2024 pm 04:14 PM

PyCharm注释神器:让代码注释变得轻松又高效导语:代码注释是程序开发中不可或缺的一部分,无论是为了方便代码阅读、协作开发,还是为了方便后续的代码维护与调试。而在Python开发中,PyCharm注释神器则为我们带来了便捷而高效的代码注释体验。本文将为大家详细介绍PyCharm注释神器的功能和使用方法,并结合具体的代码示例进行演示。一、PyCharm注释神

See all articles