Home > Backend Development > PHP Problem > What are the PHP coding standards?

What are the PHP coding standards?

青灯夜游
Release: 2023-02-26 08:12:01
Original
3819 people have browsed it

What are the PHP coding standards?

Why do we need coding standards?

In order to improve work efficiency and ensure the effectiveness and rationality of development.

In order to improve code readability and reusability, thereby saving communication costs.

php coding specifications

1. File format

●All php files use complete php tags, such as

●Pure PHP code file, no need to write at the end?>

2. File and directory naming

● Use meaningful program file names and directory names English naming

● Classes are uniformly adopted: DemoTest.class.php

● Interfaces are uniformly adopted: DemoTest.interface.php

● Others follow their own methods: demoTest.{ style}.php

● Some other files are as follows: demoTest.inc.php zend/demo.lib.php

3. File directory structure

● app Independent application

●class                                                                                                                                                                                                                                                                      class file, common class file (such as tool class)

Data file directory

● DOC program related document

● htdocs document_root

● Images picture catalog

● CSS CSS file

● js javascript file

● LIB shared class library

● Template template file

# ● upload upload file

● Manage background management file Storage catalog

## 4. Naming specifications

● The entire program is named in camel case, starting with a lowercase letter (such as: function displayName(){})

● The global variable key value has "_" on both sides, and the camel case method is used in the middle Naming (such as: $_GLOBALE['_beginTime_'])

● Common variables use the camel case method as a whole. It is recommended to add a prefix indicating the type before the variable. The uncertain type starts with a capital letter (such as: string - >$sMyName Array->$arrMyArray Object->$oMyObject Resource->$resource Boolean value->$flag)

● Function names should be meaningful and abbreviated as much as possible. It is recommended to use verb adjectives (For example: showMsg)

5. Class and interface naming

● Start with a capital letter

●Multiple words, the first letter of each word is capitalized

● Add i to the interface name (for example: iDataBase.interface.php)

6. Database name

● Do not use uppercase letters

● All data tables use lowercase letters and a unified prefix , multiple words are separated by "_" (for example: blog_user_info)

● Table fields are named in all lowercase, multiple words are separated by "_"

● Stored procedures start with proc_

● Trigger starts with tri_

● Event scheduling starts with event_

● View starts with view_

7. Habits and conventions

●Abbreviation (such as Image->img count->cnt)

●Magic number, when you need to use numbers, use define(TAX, 1.05)

8. Comment specifications

●Program comments, comment why this is done

●File comments, indicating the author, date, function

●Method and function comments, explaining the meaning of parameters

9 , Code style

● Use 4 spaces for indentation

● Use spaces on both sides of the equal sign

● Use one line per line, if it is too long, use .= splicing

●●Using PHP_EOL

For more PHP related knowledge, please visit

PHP Chinese website

!

The above is the detailed content of What are the PHP coding standards?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template