Php programming specifications, php programming

Source: Internet
Author: User

Php programming specifications, php programming

I wrote this today to remind myself that the programming process should not only have logic ideas, but also regulate the readability of the Code.

Thank you for the documents provided by me.

 

1. PHP programming specifications and coding habits mainly include the following:

1 file description

2 function body description

3 code indent

4 if omitted

5 variable Specification

6. Naming rules

Seven 10 lines and one comment

8. annotation Style

9 opening/closing Principle

2. Individual code-specifications:

1 <? 2/* 3 + Release 4 + Title: Title 5 + Author: Author 6 + Version: Version 7 + Initial-Time: Initial file creation time 8 + Last-Time: last modification time of this file + modifier name 9 + Desc: Brief description of this file 10 + ------------------------------------------------------------------------ 11 */

3. Function body description:

1 <? 2/** 3 * simple description of the function body 4 * @ author_start: Author 5 * @ author_end: modification time + modifier 6 * @ param string: $ id description 7 * @ param array: $ array description 8 * @ param array: $ num description 9 * @ return: return value description 10 */11 function Test ($ id, $ array = array (), $ num = 1) {12}

Note: The Code indent style of variable parameters in the Function

4. Code indent:

1 <? 2 $ str = 1; 3 $ info = '000000'; 4 $ version = '000000'; 5 $ name = 'test'; 6 $ I = 'hahaha '; 7 8 # generally, a row of 9 if ($ info) should be left blank in the most external if or flow control statements) {10 11} 12 13 # generally, leave a row of 14 for ($ I = 0, $ I <6, $ I ++) in the most external for or foreach fields) {15 16}

5. IF omitted

1 <? 2 # Some else operations should be omitted when exit or return exists in the process control statement of the if statement and its branch. 3 # error 4 if () {5 return false; 6} else {7 return true; 8} 9 # correct 10 if () {11 return false; 12} 13 return true;

6. variable naming in English

1 <? 2 # correct 3 $ title = 'title'; 4 $ name = 'name'; 5 $ pwd = 'Password'; 6 # error 7 $ biaoti = 'title '; 8 $ ming = 'name'; 9 $ mima = 'Password ';

7. Naming rules

1 <? 2/** 3 * in actual development, there are generally three naming methods. 4 * Note: whether it is a class name, variable, or method name, in actual development, A combination of up to three words 5 * big hump: Each letter is capitalized 6 * small hump: the first letter of the intermediate word is capitalized 7 * snake: each word is lowercase, use _ match link between words 8 */9 10 # Big hump. It is often used for class name definition 11 class Car {} 12 class BlueCar {} 13 14 # small hump, it is often used to define the method name 15 class Car {16 public function getColor () {} 17} 18 19 # snake. It is often used to define the variable name 20 $ res_id = 1; 21 $ res_name = 2;

9. annotation Style

1 <? 2. When you need to describe a piece of code in large quantities, use the following annotation Style 3/** 4 * I will explain 5 * ① process 1 6 * ② process 2 7 * ③ process 3 8 */9 10 2. When a line of code is required, for a small description, use the following annotation style 11 # This is the variable XXXX gave to ZZZZ, called CCCC12 $ name = ''; 13 14 3. When a line of code is required, during the description, the following annotation style is used: 15 $ name = ''; // Table X field 16 $ index_head =''; // homepage Request Header

10. Opening and Closing principles

In fact, this is a concept and a kind of design pattern.
To put it simply, it is a class or api that has been launched. It can be expanded externally without modifying the original file.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.