Code naming rules for PHP programming

Source: Internet
Author: User
File names: all are in lower case, and the names of classes are separated by the following line: use the method name in the upper case of the first letter to name the method name in the class: use the lower case of the first letter to name the private method and private variables in the class: the name of the function (variable name) starts with an underscore (_): all lowercase letters. the words are separated by an underscore... file names: All files must be in lower case and separated by hyphens

Class name: uses the upper-case camper name.

Method name in the class: the method is named in the lower case of the first letter.

Private methods and private variables in the class: start with an underscore

Function name (variable name): all lowercase letters separated by the following line

The following details

All the hosts files are suffixed with. class. php. They are named by the camper method and capitalized, for example, Pay. class. php;

The category class name and the Directory _ file name are consistent. For example, the Directory of the class name Zend_Autoloader is Zend/Autoloader. class. php;

The alias function uses lowercase letters and underscores. Example: get_client_ip;

The upper method uses the hump method, and the first letter is lowercase or the underline "_", for example, listComment (), _ getResource (). Generally, the method starting with an underscore is a private method;

The name of the Marker attribute uses the hump method. The first letter is lowercase or the underline "_", for example, $ username, $ _ instance. generally, attributes starting with an underscore are private attributes;

A constant named after an uppercase letter and an underscore "_", for example, "HOME_URL ";

Take a look:

1. indent and line length

Indent four spaces instead of tabs (some editors can configure a tab to represent multiple spaces, note that it is a space). each line must be about-85 characters long.

2. Control Structure

This part is the easiest to ignore and is also the most important aspect that affects the beauty of the code. The example is very detailed and has benefited a lot. the code is as follows:

 
 
 
 

3. function call. the code is as follows:

 

4. class name specification, the code is as follows:

 

5. method name specification (hump name). The code is as follows:

 

6. the code for defining arrays is as follows:

  'bar',    'spam' => 'ham',);?>

7. Notes

Http://pear.php.net/manual/en/standards.sample.php

Http://pear.php.net/manual/en/standards.header.php

8. Including Code

Use include_once or require_once at any time

Require_once 'foo. php ';

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.