찾다
php教程php手册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 stringnull 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
       {
           <...>
       }

       



성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
4 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
4 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
4 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 채팅 명령 및 사용 방법
4 몇 주 전By尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

에디트플러스 중국어 크랙 버전

에디트플러스 중국어 크랙 버전

작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

MinGW - Windows용 미니멀리스트 GNU

MinGW - Windows용 미니멀리스트 GNU

이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.