Php programming specifications (detailed description)

Source: Internet
Author: User

Php programming specifications (detailed description)

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.

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:

<? /* + -------------------------------------------------------------------- + Title: Title + Author: Author + Version: Version + Initial-Time: Initial File Creation time + Last-Time: last modification time of this file + modifier name + Desc: Brief description of this file + ----------------------------------------------------------------------*/

3. Function body description:

<? /*** Simple description of the function body * @ author_start: Author * @ author_end: modification time + modifier * @ param string: $ id Description * @ param array: $ array Description * @ param array: $ num Description * @ return: return value description */function Test ($ id, $ array = array (), $ num = 1 ){}

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

4. Code indent:

<? $ Str = 1; $ info = '000000'; $ version = '000000'; $ name = 'test'; $ I = 'hahaha '; # generally, leave a blank line in the most external if or flow control statement if ($ info) {}# generally, leave a blank line for ($ I = 0, $ I <6, $ I ++) in the most external for or foreach statements ){}

5. IF omitted

<? # Some else operations should be omitted if () {return false;} When exit or return exists in the process control statement of the if statement and its branch ;} else {return true;} # correct if () {return false;} return true;

6. variable naming in English

<? # Correct $ title = 'title'; $ name = 'name'; $ pwd = 'Password'; # error $ biaoti = 'title'; $ ming = 'name '; $ mima = 'Password ';

7. Naming rules

<? /*** In actual development, there are generally three naming methods. * Note: whether it is a class name, variable, or method name, in actual development, A combination of up to three words * big hump: uppercase letters of each word * small hump: uppercase letters of intermediate words * snake: lowercase letters of each word, use a _ between words */#, which is often used to define class Car {} class BlueCar {}#, it is often used to define class Car {public function getColor () {}}# snake-like by method name. It is often used to define variable name $ res_id = 1; $ res_name = 2;

9. annotation Style

<? 1. When you need to describe a piece of code in large quantities, use the following annotation style/*** I want to explain ** ① process 1 ** ② process 2 ** ③ process 3 */2. When you need to describe a line of code in a small amount, use the following annotation style # This is the variable XXXX gave to ZZZZ, called CCCC $ name = ''; 3. When you need to describe a line of code, use the following annotation style $ name = ''; // The Field $ index_head ='' in table X; // The 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.

The above article is based on the php programming specification (detailed description). I hope you can give us a reference and support the house of friends.

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.