PHP Coding Specification

Source: Internet
Author: User
Tags uppercase letter

1. File format
    • All PHP files use full PHP tags, such as <?php? >
    • Pure PHP code file, at the end do not need to write?>
2. File and directory naming
    • Both the program file name and the directory name are in a meaningful English name
    • Class Uniform adoption: DemoTest.class.php
    • Interface Unified Adoption: DemoTest.interface.php
    • Others in their own way: Demotest. {style}.php
    • Some other files follow: demoTest.inc.php zend/demo.lib.php
3. File directory structure
  • App-independent apps
  • class file, common class file (e.g. tool Class)
  • Conf/inc Configuration file Directory
  • Data file directory
  • Doc Program Related documentation
  • Htdocs Document_root
  • Images Picture Catalogue
  • CSS CSS Files
  • JS JavaScript file
  • Lib Common class library
  • Template templates File
  • Upload Uploading files
  • Manage background Management file storage directory
4. Naming conventions
    • The whole program is named after the hump, starting with a lowercase letter (for example: function DisplayName () {})
    • Global variable Key values have "_" on both sides, the middle using hump method named (such as: $_globale[' _begintime_ '))
    • The general variable is used as the whole hump method, it is recommended to prefix the variable with the expression type, the indeterminate type begins with an uppercase letter (for example: string-$sMyName array, $arrMyArray object, $oMyObject resource, and so on $resource Boolean value $flag)
    • Function name to make sense, as far as possible abbreviated, suggested to use verbs + adjectives (such as: showmsg)
5. Class and interface naming
    • Start with a capital letter
    • Multiple words, capitalize the first letter of each word
    • Interface naming plus I (e.g.: iDataBase.interface.php)
6. Database naming
    • No capitalization is present
    • Data tables use lowercase, uniform prefixes, multiple words with "_" intervals (e.g. Blog_user_info)
    • Table fields are all lowercase, with multiple words at "_" intervals
    • Stored procedures begin with PROC_
    • Triggers start with Tri_
    • Event Scheduler starts with Event_
    • View starts with View_
7. Habits and conventions
    • Abbreviations (e.g. image->img count->cnt)
    • Magic numbers, need to use a number when defining define (tax, 1.05)
8. Annotation specification
    • Program comments, comments why do this
    • File comments, indicating author, date, function
    • Methods and function annotations, explaining the meaning of the parameters
9. Code Style
    • Indent with 4 spaces
    • There are spaces on both sides of the equals sign
    • One line, too long to use. = Stitching
    • Using Php_eol

PHP Coding Specification

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.