Home >Backend Development >PHP Tutorial >PHP coding standards
This article shares with you the coding rules for PHP. It is very practical. Friends in need can use it as a reference.
Category:
DemoTest.class.php
Interface:
DemoTest.interface.php
Others:
demoTest.{style}.php
整体采用驼峰命名法,同时命名要有意义。
Global variables:
Use "_" on both sides, and use camel case naming in the middle
Constant:
#
Camel case naming method can be preceded by an abbreviation indicating the variable type. Accurate and meaningful English words must be used:
Array: $arrMyArray
Interface and class naming:
CamelCase nomenclature, starting with a capital letter.
For example: Class DataBase, file name: DataBase.class.php
Comments:
程序应提供必要的注释,包括文件注释,代码块注释,函数注释。
*
*/
Function comments:
//Place before function
Code block comment:
//Only write code comments where necessary to explain why, not what to do, and provide the most useful information.
Code style:
Statement line breaks:
Control the line length within 80 characters
Better practice:
Related recommendations:
How to solve php encoding conversion garbled code
Detailed explanation of PHP encoding conversion function application skills_php examples
PHP Coding Style Guide (PHP-FIG PSR-2)
The above is the detailed content of PHP coding standards. For more information, please follow other related articles on the PHP Chinese website!