If you use a third-party framework and provide code style instructions, follow its code style standards, otherwise as follows!
== Format:
* Use UTF-8 encoding
* Use 4 spaces for indentation, tabs are prohibited
* Unix style line breaks (LF)
* Used by comma, colon and semicolon operators Spaces
* Do not use spaces before (, [ after, ],)
* Use 4 spaces for indentation in code blocks
* Use hierarchical indentation
* Use a blank line before the return value of the return method (Unless there is only one line of code) and use blank lines to distinguish between two methods
* Use blank lines to distinguish between two large logical code segments
* Keep the number of lines within 80 words, no more than 120
* Use standard PHP tag delimitation, prohibit the use of short tags ( //... ?>), and prohibit the use of PHP end tags ("?>") for files that only contain PHP code
, use the comment "/* End of file
* A single line of code must also end with a semicolon (;)
== Naming:
* The file name uses snake_case. It is forbidden to use bloated file names
* Use snake_case method for variable names, and it is forbidden to use bloated variable names
* It is forbidden to use single characters as local variables (such as $i), except in for loops
* It is forbidden to use uppercase letters as Global variables, if capital letters are used, should use SCREAMING_SNAKE_CASE
* Use CamelCase for class names, and camelCase for method names (keep the capitalization of abbreviations like HTTP, RFC, and XML)
* Use SCREAMING_SNAKE_CASE for constant names
// bad superclass.php SuperClass.php superClass.php $i = "foobar"; // 单字符变量只充许使用在for循环中 $bufferdText // 驼峰式变量,并且意思可以再精简些 $groupid // 两个单词之间需要下划线分开 $name_of_last_city_used // 太长 MyConstant // 应该用下划线并且字母没有全大写 N // 单字符 S_C_VER // 意思不清楚 class superclass class superClass function fileproperties() // 意思不清楚并且没有驼峰式命名 function fileProperties() // 意思不清楚 function getfileproperties() // 好些了,但没有驼峰式命名 // good super_class.php for ($i = 0; $i < 10; $i++) $buffer $group_id $last_city MY_CONSTANT NEWLINE SUPER_CLASS_VERSION class SuperClass function getFileProperties()
== Syntax:
For PHP code embedded in HTML, for code blocks like if, for, foreach, while, etc., use if: ... endif; for: ... endfor; foreach: ... endforeach; and while: ... endwhile;Method block
Php code
...
isLoggedIn()): // checking logged in ?>
< !-- HTML goes here. -->
Blocks must be compatible with phpDocumentor format, please refer to: http://phpdoc.org/
* Avoid redundant comments
Php code
/**
* Controller class description information
*/
class Controller {
private static $instance;
public function __construct() {
...
}
/**
*/
public static function &get_instance() {
/* End of file controller.php */
== Others:
* Keep the code simple
* Keep it consistent