Naming principles for PHP development

Source: Internet
Author: User
The big camper rule means that the class names are case-sensitive and the first letter of each word is capitalized. Use full words whenever possible to avoid acronyms (unless the acronyms are more widely used, such as URLs and HTML)

N naming principles:

The big camper rule means that the class names are case-sensitive and the first letter of each word is capitalized. Use the complete word whenever possible to avoid acronyms (unless the acronyms are more widely used, such as URLs and HTML.

Class n attributes:

Small hump rules. We recommend that you name the attribute with the character 'm' as the prefix. The prefix 'M' follows the same class naming rule. 'M' always acts as a modifier at the beginning of the name, just like a reference starting with 'R. The reason for doing so: the prefix 'M' prevents any conflicts between class attributes and method names. Your method name and attribute name are often very similar, especially for accessing elements. It is recommended that the private variable start with _ (underline.

Class n method naming:

Small hump rules. The method name is usually a verb. it is a combination of upper and lower cases. The first letter of the first word is lowercase, and the last letter is capitalized. Every method in the class executes an action, so the name of it should clearly indicate what it is doing: replace errorCheck () with checkForErrors (), and use dumpDataToFile () replace dataFile (). By doing so, we can roughly understand the logic processing in this method ., The private method should start with _ (underline.

N variable name:

Variables in PHP are case sensitive. It is recommended that all letters are in lower case, and the words are separated by underscores (_). the variable names start with letters and underscores. It cannot start with a number or a special symbol such as @ $. Variable names should be brief and descriptive. Avoid the variable name of a single character unless it is a one-time temporary variable.

N constant name:

Whether it is a class constant or a common constant outside the class, we recommend that you use uppercase letters to separate words with underscores.

N function name:

The naming principles of functions outside the class are different from those of class methods. It is recommended that all characters are in lower case and words are separated by underscores.

N interface name:

The interface name is prefixed with the uppercase letter 'I. A mix of upper and lower cases is followed, and the first letter of each word is capitalized.

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.