Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the PHP development specifications?

Shulou Source: shulou.com Published: 2022-06-03 09:05:28 09月16日 Update

This article focuses on "what are the PHP development specifications", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the PHP development specifications"?

Source file

Code usage

The file format must be without BOM UTF-8 format

A file declares only one type. For example, class and interface cannot be mixed in a source file.

Indent

Use 4 spaces to indent, IDE can set

Line length

120 characters per line

Keyword

All keywords are lowercase, such as true, false

Naming

The class is called the big hump method, such as UserModel

The class method is called small hump method, such as getUserId ()

Functions are combined with lowercase letters, such as get_cookie ()

Variable names use the small hump method, such as $userId

A constant is defined as a combination of uppercase letters plus _, such as IS_DEBUG

Code comment tag

Annotate classes, methods, and properties in the class file, using @ param @ return @ throwns

@ param comment to write a detailed explanation, such as @ param string $username user name

Service module

Routes are composed of lowercase letters plus _, such as / api/get_user_info

The View layer is responsible for data presentation.

The Controller layer is responsible for input parameter verification, the outermost layer catches exceptions, and calls Logic and View view layers.

The Logic layer is responsible for the specific business logic, calls the Model layer, and returns the processing data

The Model layer is responsible for data table query and association.

Exception classes need to distinguish functions. For example, ParamException indicates parameter error, and UserException indicates custom exception.

For exceptions, you need to classify and define code, and use PHP class constants instead, such as

Tags: Data files examples development letters characters lowercase constants datasheets methods times comments humps business code keys keywords content parameters fields Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Apple Linux MariaDB Shulou Tech Info