PHP Naming conventions

Source: Internet
Author: User

A framework written using PHP must have its own specifications, thinkphp and vice versa. Here are The naming conventions that should be followed as much as possible using thinkphp:

class 2 files are suffixed with . class.php (This is the thinkphp A class library file used internally, which does not represent an externally loaded class library file, is named with the Hump method and capitalized, such as DbMysql.class.php.

2 other class library files, such as functions, configuration files, are generally . PHP as a suffix (the third party introduces no requirements).

2 ensure that file naming and invocation are case-sensitive because the class Unix on the system, the case is sensitive (and thinkphp Under debug mode, even in the Windows The platform is also strictly checked for capitalization).

2  the class name and file name are the same (including the above capitalization), such as useraction.class.php , infomodel infomodel.class.php ,

2 the naming of functions uses lowercase letters and underscores, for example get_client_ip

2 Action Controller class to Action is a suffix, for example useraction , infoaction

2 model classes are suffixed with models, such as Usermodel , Infomodel

2 the name of the method uses the Hump method, and the first letter is lowercase, for example GetUserName

2 the name of the property is used by the Hump method, and the first letter is lowercase, for example TableName

2 Double underline " __ "The beginning of a function or method as a magical method, such as __call and the __autoload

2 constants are named with uppercase letters and underscores, for example Has_one and the Many_to_many

2 The configuration parameters are named with uppercase letters and underscores, for example html_cache_on

2 language variables are named with uppercase letters and underscores, such as My_lang, where a language variable that starts with an underscore is typically used for system language variables, such as _class _not_exist_.

2 data tables and fields are named with lowercase underlines, such as Think_user and the user_name

Exception:

in the thinkphp inside, there is a special case of a function name, which is a single-letter capitalization function, which is usually a shortcut to some operations, or a special function. For example,ADSL methods and so on, they have a special meaning, there will be some understanding.

another point, thinkphp Default Usage UTF-8 code, so make sure your program files are using the UTF-8 encoding format, and remove BOM Information Header (remove BOM header information in many ways, different editors have a setup method, you can also use the tool for unified detection and processing.

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.