php 参数 注释

Jun 23, 2016 pm 02:30 PM

简介:这是php 参数 注释的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。

class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=340853' scrolling='no'>

所有的文档性注释都是由/**开始的一个多行注释,在phpDocumentor里称为DocBlock, DocBlock是指软件开发人员编写的关于某个关键字的帮助信息,使得其他人能够通过它知道这个关键字的具体用途,如何使用。 PhpDocumentor规定一个DocBlock包含如下信息:<br>1. 功能简述区<br>2. 详细说明区<br>3. 标记tag<br>文档性注释的第一行是功能描述区,正文一般是简明扼要地说明这个类,方法或者函数的功能,功能简述的正文在生成的文档中将显示在索引区。功能描述区的内容可以通过一个空行或者 . 来结束<br>在功能描述区后是一个空行,接着是详细说明区,. 这部分主要是详细说明你的API的功能,用途,如果可能,也可以有用法举例等等。在这部分,你应该着重阐明你的API函数或者方法的通常的用途,用法,并且指明是否是跨平台的(如果涉及到),对于和平台相关的信息,你要和那些通用的信息区别对待,通常的做法是另起一行,然后写出在某个特定平台上的注意事项或者是特别的信息,这些信息应该足够,以便你的读者能够编写相应的测试信息,比如边界条件,参数范围,断点等等。<br>之后同样是一个空白行,然后是文档的标记tag,指明一些技术上的信息,主要是最主要的是调用参数类型,返回值极其类型,继承关系,相关方法/函数等等。<br>关于文档标记,详细的请参考第四节:文档标记。<br>文档注释中还可以使用例如 这样的标签,详细介绍请参考附录二。&lt;br&gt;下面是一个文档注释的例子

/**<br>* 函数add,实现两个数的加法<br>*<br>* 一个简单的加法计算,函数接受两个数a、b,返回他们的和c<br>*<br>* @param int 加数<br>* @param int 被加数<br>* @return integer<br>*/<br>function Add($a, $b) {<br>return $a+$b;<br>}

生成文档如下:<br>Add<br>integer Add( int $a, int $b)<br>[line 45]<br>函数add,实现两个数的加法<br>Constants 一个简单的加法计算,函数接受两个数a、b,返回他们的和c<br>Parameters<br>? int $a - 加数<br>? int $b - 被加数<br>5.文档标记:<br>文档标记的使用范围是指该标记可以用来修饰的关键字,或其他文档标记。<br>所有的文档标记都是在每一行的 * 后面以@开头。如果在一段话的中间出来@的标记,这个标记将会被当做普通内容而被忽略掉。<br>@access<br>使用范围:class,function,var,define,module<br>该标记用于指明关键字的存取权限:private、public或proteced<br>@author<br>指明作者<br>@copyright<br>使用范围:class,function,var,defi

使用范围:define<br>用来指明php中define的常量<br>@final<br>使用范围:class,function,var<br>指明关键字是一个最终的类、方法、属性,禁止派生、修改。<br>@filesource<br>和example类似,只不过该标记将直接读取当前解析的php文件的内容并显示。<br>@global<br>指明在此函数中引用的全局变量<br>@ingore<br>用于在文档中忽略指定的关键字<br>@license<br>相当于html标签中的,首先是URL,接着是要显示的内容<br>例如百度<br>可以写作 @license http://www.baidu.com 百度<br>@link<br>类似于license<br>但还可以通过link指到文档中的任何一个关键字<br>@name<br>为关键字指定一个别名。<br>@package<br>使用范围:页面级别的-> define,function,include<br>类级别的->class,var,methods<br>用于逻辑上将一个或几个关键字分到一组。<br>@abstrcut<br>说明当前类是一个抽象类<br>@param<br>指明一个函数的参数<br>@return<br>指明一个方法或函数的返回指<br>@static<br>指明关建字是静态的。<br>@var<br>指明变量类型<br>@version<br>指明版本信息<br>@todo<br>指明应该改进或没有实现的地方<br>@throws<br>指明此函数可能抛出的错误异常,极其发生的情况<br>上面提到过,普通的文档标记标记必须在每行的开头以@标记,除此之外,还有一种标记叫做inline tag,用{@}表示,具体包括以下几种:<br>{@link}<br>用法同@link<br>{@source}<br>显示一段函数或方法的内容<br>6.一些注释规范<br>a.注释必须是<br>/**<br>* XXXXXXX<br>*/<br>的形式<br>b.对于引用了全局变量的函数,必须使用glboal标记。<br>c.对于变量,必须用var标记其类型(int,string,bool...)<br>d.函数必须通过param和return标记指明其参数和返回值<br>e.对于出现两次或两次以上的关键字,要通过ingore忽略掉多余的,只保留一个即可<br>f.调用了其他函数或类的地方,要使用link或其他标记链接到相应的部分,便于文档的阅读。<br>g.必要的地方使用非文档性注释,提高代码易读性。<br>h.描述性内容尽量简明扼要,尽可能使用短语而非句子。<br>i.全局变量,静态变量和常量必须用相应标记说明<br>7. 总结<br>phpDocumentor是一个非常强大的文档自动生成工具,利用它可以帮助我们编写规范的注释,生成易于理解,结构清晰的文档,对我们的代码升级,维护,移交等都有非常大的帮助。<br>关于phpDocumentor更为详细的说明,可以到它的官方网站<br>http://manual.phpdoc.org/查阅<br>8.附录<br>附录1:<br>能够被phpdoc识别的关键字:<br>Include<br>Require<br>include_once<br>require_once<br>define<br>function<br>global<br>class<br>附录2<br>文档中可以使用的标签<br><br>&lt;br&gt;&lt;br&gt;&lt;br&gt;<kdb>&lt;br&gt;<li> &lt;br&gt;<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">&lt;br&gt;</pre><div class="contentsignin">Copy after login</div></div> <ul> &lt;br&gt;<samp>&lt;br&gt;<var>&lt;br&gt;附录三:&lt;br&gt;一段含有规范注释的php代码 :</var></samp> </ul> </li></kdb>

<?php/*** Sample File 2, phpDocumentor Quickstart** This file demonstrates the rich information that can be included in* in-code documentation through DocBlocks and tags.* @author Greg Beaver <cellog@php.net>* @version 1.0* @package sample*/// sample file #1/*** Dummy include value, to demonstrate the parsing power of phpDocumentor*/include_once 'sample3.php';/*** Special global variable declaration DocBlock* @global integer $GLOBALS['_myvar']* @name $_myvar*/$GLOBALS['_myvar'] = 6;/*** Constants*//*** first constant*/define('testing', 6);/*** second constant*/define('anotherconstant', strlen('hello'));/*** A sample function docblock* @global string document the fact that this function uses $_myvar* @staticvar integer $staticvar this is actually what is returned* @param string $param1 name to declare* @param string $param2 value of the name* @return integer*/function firstFunc($param1, $param2 = 'optional') {/*** A sample private variable, this can be hidden with the --parseprivate* option* @accessprivate* @var integer|string*/var $firstvar = 6;/*** @link http://www.example.com Example link* @see myclass()* @uses testing, anotherconstant* @var array*/var $secondvar =array(    'stuff' =>                 array(                                   6,                                   17,                                   'armadillo'                           ),     testing => anotherconstant);/*** Constructor sets up {@link $firstvar}*/function myclass() {$this->firstvar = 7;}/*** Return a thingie based on $paramie* @param boolean $paramie* @return integer|babyclass*/function parentfunc($paramie) {if ($paramie) {return 6;} else {return new babyclass;}}}/*** @package sample1*/class babyclass extends myclass {/*** The answer to Life, the Universe and Everything* @var integer*/var $secondvar = 42;/*** Configuration values* @var array*/var $thirdvar;/*** Calls parent constructor, then increments {@link $firstvar}*/function babyclass() {parent::myclass();$this->firstvar++;}/*** This always returns a myclass* @param ignored $paramie* @return myclass*/function parentfunc($paramie) {return new myclass;}}?>
Copy after login

爱J2EE关注Java迈克尔杰克逊视频站JSON在线工具

http://biancheng.dnbcw.info/php/340853.html pageNo:6
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)

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

See all articles