Home php教程 php手册 PHP comment syntax specifications and naming conventions

PHP comment syntax specifications and naming conventions

May 16, 2016 am 09:00 AM
php comments

comments are very important in the process of writing code. good comments can make your code easier to read. when writing code, you must pay attention to the specifications of comments. here, the editor of script house will sort it out for you. friends in need can refer to it.

hp comment specification

comments are very important in the process of writing code , good comments can make your code easier to read. be sure to pay attention to the specifications of comments when writing code.

“php is an extremely easy language to get started with. a novice who has just started may be able to use echo to print out a hello world in less than a few minutes! but is he a real programmer? how? how to define a programmer? if you want to truly become a programmer, you must follow a set of program writing specifications."

we often write some functions, but these functions may only be understood by ourselves. even after a while, i no longer recognize what i wrote, so what should i do? the best way is of course to add comments to your code.

we may be familiar with many comment writing methods, such as c pear php comments, etc., but the ones we mainly 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 comment out a function in a standard way?

/**
* @name 名字
* @abstract 申明变量/类/方法
* @access 指明这个变量、类、函数/方法的存取权限
* @author 函数作者的名字和邮箱地址
* @category 组织packages
* @copyright 指明版权信息
* @const 指明常量
* @deprecate 指明不推荐或者是废弃的信息
* @example 示例
* @exclude 指明当前的注释将不进行分析,不出现在文挡中
* @final 指明这是一个最终的类、方法、属性,禁止派生、修改。
* @global 指明在此函数中引用的全局变量
* @include 指明包含的文件的信息
* @link 定义在线连接
* @module 定义归属的模块信息
* @modulegroup 定义归属的模块组
* @package 定义归属的包的信息
* @param 定义函数或者方法的参数信息
* @return 定义函数或者方法的返回信息
* @see 定义需要参考的函数、变量,并加入相应的超级连接。
* @since 指明该api函数或者方法是从哪个版本开始引入的
* @static 指明变量、类、函数是静态的。
* @throws 指明此函数可能抛出的错误异常,极其发生的情况
* @todo 指明应该改进或没有实现的地方
* @var 定义说明变量/属性。
* @version 定义版本信息
*/
Copy after login

the information in the comments is very comprehensive, and there may be a lot of it that we don’t use. the red parts are the ones we often use.

example: several common comment methods in php:

1. file comments, introducing the file name, function, author version number and other information

/**
* 文件名简单介绍
* 
* 文件功能
* @author 作者
* @version 版本号
* @date 2020-02-02
*/
Copy after login

file header template

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

2. class comments, class name and introduction

/**
* 类的介绍
* 
* 类的详细介绍(可选)
* @author 作者
* @version 版本号
* @date 2020-02-02
*/
Copy after login
/** 
* 类的介绍 
* 
* 类的详细介绍(可选。)。 
* @author     richard<e421083458@163.com> 
* @since     1.0 
*/ 
class test  
{ 
}
Copy after login

3. function comments, function function, parameter introduction and return type

/**
* 函数的含义说明
* 
* @access public 
* @author 作者
* @param mixed $arg1 参数一的说明 
* @param mixed $arg2 参数二的说明
* @return array 返回类型
* @date 2020-02-02
*/
Copy after login

function header comments

/** 
* 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();}
Copy after login

program code comments

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

2. several statements serve as a logical code block, and the comments of this block can use the /* */ method.

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

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

php naming convention

1 .directories and files

directories use lowercase underscores
class libraries and function files are all suffixed with .php
the file names of classes are all defined in namespaces, and the paths of the namespaces and the path of the class library file is consistent
class files are named using camel case (the first letter is capitalized), and other files are named with lowercase underscores
the class name and class file name are consistent, and uniformly use camel case (the first letter is capitalized)

2. functions and classes, attribute naming

classes are named using camel case (the first letter is capitalized), such as user, usertype, and no suffix is ​​required by default. for example, usercontroller should be directly named user
functions are named using lowercase letters and underscores (starting with a lowercase letter) for example, the name of the get_client_ip
method uses camel case (the first letter is lowercase), such as getusername (if the method has a return value, it is currently customary to use the first letter of the attribute type in lowercase, such as s (string), i (int), f (float), b (boolean), a (array), etc.)
the naming of attributes uses camel case (the first letter is lowercase), such as tablename, instance (it is currently customary to use lowercase for the first letter) attribute types, such as s (string), i (int), f (float), b (boolean), a (array), etc.)
functions or methods starting with double underscore "__" are used as magic methods, for example __call and __autoload

3. constants and configurations

constant names are named with uppercase letters and underscores, such as app_path and think_path
configuration parameters are named with lowercase letters and underscores, for example url_route_on and url_convert

4. data table box fields

data tables and fields are named in lowercase and underlined, and be careful not to start the field name with an underscore, such as the think_user table and user_name field. it is not recommended to use camel case and chinese as data table field names.

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

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)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

PHP comments revealed: detailed comparison of single-line comments and multi-line comments PHP comments revealed: detailed comparison of single-line comments and multi-line comments Mar 15, 2024 pm 12:51 PM

The Secret of PHP Comments: Detailed Comparison of Single-line Comments and Multi-line Comments PHP is a widely used web development language, in which the use of comments plays a vital role in the readability and maintainability of the code. In PHP, common comments come in two forms: single-line comments and multi-line comments. This article will compare these two annotation forms in detail and provide specific code examples to help readers better understand their usage and differences. 1. Single-line comments A single-line comment is to add a line of comments in the code, starting with // and going to the end of the line. Single line comments

What are the types of php comments? What are the types of php comments? Aug 23, 2023 pm 01:46 PM

The types of PHP comments include single-line comments, multi-line comments, document comments, conditional comments, etc. Detailed introduction: 1. A single line comment starts with a double slash "//" and is used to comment a single line of code. In this comment type, everything from the beginning of the double slash to the end of the line will be regarded as a comment, not Will be interpreted as code; 2. Multi-line comments start with a slash asterisk "/" and end with an asterisk slash "*/". This comment type can be used to comment a piece of code or multiple lines of code; 3. Documentation comments It also starts with a slash-asterisk "/", ends with an asterisk-slash "*/", and so on.

Code comments in PHP Code comments in PHP May 23, 2023 am 08:27 AM

Code comments are text reminders that programmers add when writing code to make it easier for themselves and other programmers to read and understand the code. In PHP, code comments are indispensable. This article will introduce in detail the types, specifications and uses of code comments in PHP. 1. Code comment types in PHP In PHP, there are three types of comments: single-line comments, multi-line comments and documentation comments. Single-line comments A single-line comment starts with a double slash "//" and ends at the end of the line. For example: //This is a single line comment multi-line comment multi-line comment ends with "

Detailed explanation of PHP comment types: single-line comments and multi-line comments Detailed explanation of PHP comment types: single-line comments and multi-line comments Mar 15, 2024 pm 05:27 PM

PHP is a popular server-side scripting language widely used in the field of web development. In the code writing process, comments are a very important element, which can help developers better understand the code and improve the readability and maintainability of the code. This article will introduce the comment types in PHP in detail, including single-line comments and multi-line comments, and provide specific code examples. Single-line comments In PHP, single-line comments can be achieved by using double slashes //. Single-line comments start with // and continue to the end of the line. Single-line comments are often used to comment on code

What are the types of comments in php What are the types of comments in php Jul 25, 2023 pm 02:26 PM

The types of comments in PHP are: 1. Single-line comments, used to explain a certain function, remind other developers or yourself to pay attention, etc.; 2. Multi-line comments, used to explain multi-line code blocks in detail; 3. Document comments , used to provide a detailed description of the entire code block or function or method.

A closer look at PHP comments: the difference between single-line and multi-line comments A closer look at PHP comments: the difference between single-line and multi-line comments Mar 15, 2024 pm 05:15 PM

When entering the field of PHP programming, comments are a very important concept. When writing code, comments are crucial to clarify the intent of the code, help other developers understand the code logic, and facilitate yourself to maintain the code in the future. In PHP, comments are divided into single-line comments and multi-line comments, and there are some differences in usage. This article will deeply explore the characteristics of PHP comments and the use of single-line comments and multi-line comments, and illustrate it through specific code examples. 1. Single-line comments A single-line comment is to add a line of comments to the code to explain

How to use comments in PHP to enhance code readability and understandability How to use comments in PHP to enhance code readability and understandability Jul 15, 2023 pm 09:27 PM

How to use comments in PHP to enhance code readability and understandability Introduction: During the development process, comments are a very important component that can help developers better understand the code and improve the readability and maintainability of the code. . This article will introduce how to use comments in PHP to enhance the readability and understandability of code, and provide some practical code examples. Single-line comments Single-line comments are used to explain and illustrate a certain line of code. In PHP, single-line comments start with double slashes (//) and end at the end of the line. Here is an example

PHP Comment Specification: How to use documentation comments to write API documentation PHP Comment Specification: How to use documentation comments to write API documentation Jul 30, 2023 pm 07:00 PM

PHP Comment Specification: How to use documentation comments to write API documentation Introduction: When developing PHP applications, writing complete API documentation is very important for the development team and other developers. Good documentation improves code readability and maintainability, and promotes teamwork and information sharing. This article will introduce how to use documentation comments to write PHP API documentation, and provide some sample code to help readers understand how to write comments in a standardized way. Comment specification In PHP, we use comments to explain and describe the code. generally

See all articles