Home  >  Article  >  Backend Development  >  How to annotate in PHP

How to annotate in PHP

青灯夜游
青灯夜游Original
2019-01-22 15:35:4217951browse

It is necessary to comment in the code. Standard comments make the source code easier for humans to understand, and can help us understand the code written by others or ourselves before. So how to do code comments? This article will introduce you to several methods of annotating in PHP. I hope it will be helpful to you.

How to annotate in PHP

Comments are usually written within a block of PHP code. It is a non-executable line that does not appear in the output and is usually ignored by compilers and interpreters; that is Say, the browser does not read or parse the comments. [Video tutorial recommendation: PHP tutorial]

There are two types of comments that can be made in PHP:

Single line Comment:

Each line must be marked with a separate comment, which is called a single-line comment. It is used for brief description. Single-line comment declarations are of two types: starting with (#) or backslash (//)

<?php
//第一行注释
echo "HELLO";
echo "<br> ";
#第二行注释
echo "PHP中文网";
?>

In the above example, the first line of comments starts with (//) and the fourth line with a pound sign (#)beginning.

Output:

How to annotate in PHP

Description: The most widely used method for single-line comments is to use double slashes (//)

Multi-line comments:

Multi-line comments are used to comment multiple lines and are often used in comments on multi-line text. The text of batch comments needs to be included in (/*.....*/), starting with /* and ending with */.

<?php
/* 以下代码行
 将输出“Hello World!”  */
echo "Hello Worldn!";
?>

Description: Multi-line comments are often used by developers

Why comments are needed

Comments serve to explain the code. It will help us and others in the future understand what this piece of code does and what it does; it will also provide an easier maintenance plan for the author or third party, which will be of great help for subsequent maintenance.

Another highlight of comments is the generation of technical documentation. In fact, some applications, such as PHP Documentor, rely on specific syntax annotations to generate the application's documentation. This ensures significant time savings for the development team.

The above is the entire content of this article, I hope it will be helpful to everyone's study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !

The above is the detailed content of How to annotate in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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