


Detailed explanation of PHP comment syntax specifications and naming conventions
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 who need it can refer to
HP comment specifications
Comments are very important in the process of writing code. Good comments can make your code easier to read. When writing code, be sure to pay attention to the specification of comments.
"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 to do it? What about defining 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, or even It’s been a while since I didn’t 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 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 declares a variable/class/method
* @access specifies the access rights of this variable, class, function/method
* @author the 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 indicates the global variable referenced in this function
* @include indicates the information of the included file
* @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 description variables/attributes.
* @version defines 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: 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 */
File header template
/** *这是一个什么文件 * *此文件程序用来做什么的(详细说明,可选。)。 * @author richard<e421083458@163.com> * @version $Id$ * @since 1.0 */
2. Class comments, class name and introduction
/** * 类的介绍 * * 类的详细介绍(可选) * @author 作者 * @version 版本号 * @date 2020-02-02 */
/** * 类的介绍 * * 类的详细介绍(可选。)。 * @author richard<e421083458@163.com> * @since 1.0 */ class Test { }
3. Function comments, function functions, parameter introduction and return type
/** * 函数的含义说明 * * @access public * @author 作者 * @param mixed $arg1 参数一的说明 * @param mixed $arg2 参数二的说明 * @return array 返回类型 * @date 2020-02-02 */
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();}
##Program code comments1. The principle of comments is to explain the problem clearly, not more is 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();
PHP naming convention
1. Directories and filesUse lowercase underscores for directoriesClass libraries and function files are uniformly suffixed with .php
The file names of classes are defined in namespaces, and the path of the namespace is consistent with the path of the class library file
Class files are named using camel case (the first letter Uppercase), other files are named with lowercase underscores
The class name and the class file name are consistent, and the camel case method is uniformly used (the first letter is capitalized)
. Functions are named using lowercase letters and underscores (starting with a lowercase letter), such as get_client_ip
Method naming uses camel case (the first letter is lowercase), such as getUserName (if the method has a return value, it is currently customary to use lowercase attribute types with the first letter, such as s (string), i (int), f ( float), b (boolean), a (array), etc.)
Use camel case naming of attributes (the first letter is lowercase), such as tableName, instance (it is currently customary to use lowercase attribute types with the first letter, 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, such as __call and __autoload
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, such as url_route_on and url_convert
4. Data table box fields
Data Tables and fields are named in lowercase and underlined, and field names should not start 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.
Articles you may be interested in:
php language comments, single-line comments and Related content of multi-line comments
phpstorm regular matching to delete empty lines and comment lines
Parse Laravel through source code Dependency injection related content
#
The above is the detailed content of Detailed explanation of PHP comment syntax specifications and naming conventions. For more information, please follow other related articles on the PHP Chinese website!

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
