Customary PHP Naming conventions

Source: Internet
Author: User

From C + + to PHP has been a long time, has been a bit of code cleanliness, for the file name, interface name, class name, method name, etc. use strict hump naming method,

But sometimes you hesitate to use the initial capitalization to differentiate or underline. Briefly summarize and statute today.

1. File name

File name Unified use of the big hump nomenclature, that is, the first letter of all words are capitalized, such as: userlogincontroller.php

2. Class name

The class name also uses the big hump name method, the length as far as possible to control within five words, if the logic description is too, then uses the abbreviation form, for example: Class account, Class Realnameverify.

3. Class Method Name

The class method name uses the small hump nomenclature, that is, the first word is all lowercase, followed by the first letter capitalized, and the first letter as far as possible to describe the type of operation, such as: GetUserInfo, Updategameconfig, Bindphone.

For private methods of a class, you should start with a single underscore, such as: _guestlogin

4. Class member variables and method variables

Although many people argue that class member variables already start with M, it is customary for all variables to be defined in the form of a lowercase machine's underline link, such as: $game _repository, $table _config, $return _data.

Incidentally, the better variable naming method:

1. The member variable starts with m, such as: $mTable, $MURL

2. The static variable starts with s, such as: $sCount, $sStatus

3. Global variables start with G, such as: $gConnectTime

5. Class constants, global constants

For constants, use all uppercase letters and underline the way words are concatenated, such as: Payment_method_ttbank.

Finally, there is no absolute best naming specification, only the most suitable for the team's naming convention, the specific detailed naming rules should be based on the use of the framework, the specific project background, etc. to make corresponding changes.

But a unified, clear, simple naming convention is useful for project development and maintenance.

Customary PHP Naming conventions

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.