search
HomeBackend DevelopmentPHP TutorialSpecification guidelines for standard comments in PHP programs

As a language that is relatively easy to get started, many people can easily get started with php, but in the process of learning, you must also abide by PHP's standard comment specifications.

We often write some functions, but these functions may only be understood by ourselves. After a while, we may even not recognize what we wrote. So what should we do? The best way is of course to add comments to your code.

We may be familiar with many ways of writing comments, C pear PHP comments, etc., but the main ones we use are # and /**/.

# is a short comment method. Maybe you will use it to annotate a variable or call a method. /**/. We may still use it to comment out a large section of code. , but how to use it to standardly annotate a function?

/**
* @name Name
* @abstract Declaration of variables/classes/methods
* @access Specifies the access rights of this variable, class, function/method
* @author Name and email address of the function author Address

* @category Organization packages
* @copyright Specify copyright information
* @const Specify constant
* @deprecate Specify deprecated or obsolete information
* @example Example
* @exclude indicates that the current comment will not be analyzed and will not appear in the document
* @final indicates that this is a final class, method, or attribute, and derivation and modification are prohibited.
* @global specifies the global variables referenced in this function
* @include specifies the information of the included files
* @link defines the online connection
* @module defines the attributed module information
* @modulegroup defines the belonging module group
* @package defines the belonging package information
* @param defines the parameter information of the function or method
* @return defines the return information of the function or method
* @see defines the functions and variables that need to be referenced, and adds the corresponding hyperlinks.
* @since indicates which version the api function or method was introduced from.
* @static indicates that variables, classes, and functions are static.
* @throws Indicates the error exceptions that this function may throw, and the circumstances in which they occur
* @todo Indicates areas that should be improved or not implemented
* @var defines variables/attributes.
* @version Define version information
*/

The information in the comments is very comprehensive. There may be a lot that we don’t use. The red parts are the ones we often use.

Example:

File header template

/** 
*这是一个什么文件 
* 
*此文件程序用来做什么的(详细说明,可选。)。 
* @author      richard<e421083458@163.com> 
* @version     $Id$ 
* @since        1.0 
*/

Function header comment

/** 
* some_func  
* 函数的含义说明 
* 
* @access public 
* @param mixed $arg1 参数一的说明 
* @param mixed $arg2 参数二的说明 
* @param mixed $mixed 这是一个混合类型 
* @since 1.0 
* @return array 
*/  
public function thisIsFunction($string, $integer, $mixed) {return array();}

Class comments

/** 
* 类的介绍 
* 
* 类的详细介绍(可选。)。 
* @author         richard<e421083458@163.com> 
* @since          1.0 
*/  
class Test   
{  
}

Program code comments

1. The principle of comments is to explain the problem clearly, not the more the better.

2. Several statements are used as a logical code block, and the comments of this block can be used in /* */ mode.

3. For comments specific to a certain statement, you can use end-of-line comments: //.

/* 生成配置文件、数据文件。*/  
  
$this->setConfig();  
$this->createConfigFile();  //创建配置文件  
$this->clearCache();         // 清除缓存文件  
$this->createDataFiles();   // 生成数据文件  
$this->prepareProxys();  
$this->restart();

Related recommendations:

Comments in PHP, PHP comments

The above is the detailed content of Specification guidelines for standard comments in PHP programs. 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
11 Best PHP URL Shortener Scripts (Free and Premium)11 Best PHP URL Shortener Scripts (Free and Premium)Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, ReactBuild a React App With a Laravel Back End: Part 2, ReactMar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation SurveyAnnouncement of 2025 PHP Situation SurveyMar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

Notifications in LaravelNotifications in LaravelMar 04, 2025 am 09:22 AM

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft