Home > Backend Development > PHP Tutorial > Comment tags that every PHPer should master!

Comment tags that every PHPer should master!

藏色散人
Release: 2023-04-09 16:52:02
forward
5348 people have browsed it

Recommended: "PHP Video Tutorial"

Preface

Comment tags play a very important role in code comments Large and good annotation tags can give you a better and more comfortable experience in the programming process, so today I am going to sort out these tags and display them in the form of pictures and texts. On the one hand, it is to help myself understand these annotation tags. A summary. On the other hand, I also hope that everyone can better understand the comment tags

Everyone hopes to write beautiful code. Maybe you are only one tag away from beautiful code

Common tags

# #Static variables used in classes and functions@subpackage@throws@todo@var@version

A lot of the above are actually needed to be added when creating files and classes. Today I will mainly explain the commonly used tags.

@param

Description

Parameters, used for tags in function and method comments\
Format@param [Type] [name] [&lt ;description>]\
For example@param string title Article title

Code example

Comment tags that every PHPer should master!

@return

Description

Return value
Format @return [type] []]
For example @return array result array

Code example

Comment tags that every PHPer should master!

@deprecated

Description

Not recommended, expired, and will be deleted\
Format@ deprecated [<version number>] [<description>]</description></version>\
For example@deprecated 1.0.0 New versions will no longer contain this function\
if it is Replaced by other methods, it is recommended to add @see tag

Code example

Comment tags that every PHPer should master!

@see

Explanation

Reference, similar to @link, can be linked with @deprecated
Format @see [url or complete method name] []
For example @see \yii\base\db: :tableName() The old method table_name has been deprecated, please use this method instead

Code example

Comment tags that every PHPer should master!

@link

Description

Links can be used to assist explanations, reference documents, etc.\
Format@link [url] [<description>]</description>\
For example@link http:/ /g.cn If you don’t understand, go ask Google and don’t bother me

Code examples

Comment tags that every PHPer should master!

@link&@see difference

Tag Use Description
@abstract
Variables and methods of abstract classes
@access public , private or protected Access and usage rights of the document. @access private indicates that the document is protected.
@author 张三zhangsan@163.com Document author
@copyright Name time Document copyright information
@deprecated version Deprecated method in the document
@deprec
Same as @deprecated
@example /path/to/example The location of the example file saved externally to the document.
@exception
For exceptions thrown by methods in the document, you can also refer to @throws.
@global Type: $globalvarname Global variables and related methods and functions in the document
@ignore
Ignore keywords specified in the document
@internal
Development Team internal information
#@link URL Similar to license but you can also find more detailed information in the document through the link
@name Variable alias Specify an alias for a variable
@magic
phpdoc.de compatibility
@package The name of the encapsulated package A set of related classes, Function encapsulated package name
@param such as $username username variable meaning comment
@return If the function returns a bool function returns a description of the result, it is generally not used in a void (empty return result) function
@see Such as Class Login() Any element associated with the file (global variables, including pages, classes, functions, definitions, methods, variables).
@since version Record when changes were made to which parts of the document
@static
Record static classes and methods
@staticvar

##Sub version

Exception thrown by a certain method

Indicates areas where the file is incomplete or needs to be improved
type Variables in the document and their types

Version information of documents, classes, and functions
- @see @link
External link
Internal program X

@var

Description

Variable\
Format@var [Type] [Variable name] [<description>]</description>\
For example@var int id user id

Variable list

##float/doublenumber/floating point numberobjectObject instancespecifiedTypeSpecified classmixedAny typearray/specifiedType[]Array, can be specified as an array of the specified typeresourceFile resource typevoidNo return valuenull-callableExecutable callback functionfunctionNo A method that must be executedself/$thisCurrent instance
Variable type Description
string String
integer/int number/int type
boolean/bool false/true
Code example

1. Variable definition outside the method


Comment tags that every PHPer should master!2. Variable definition inside the method

Comment tags that every PHPer should master!

@throws

Description

Types of errors that may be thrown\

Format
@throws [Type] []\For example
@throws Exception

##                                                                 

The above is the detailed content of Comment tags that every PHPer should master!. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template