Backend Development 5 min read

Overview of PHP Standard Recommendations (PSR) and Key Standards

The article introduces PHP Standard Recommendations (PSR) created by PHP‑FIG, outlines their purpose in improving code quality, and summarizes key standards such as naming conventions, autoloading, coding style, logging, caching, HTTP messages, and dependency injection for backend development.

php中文网 Courses
php中文网 Courses
php中文网 Courses
Overview of PHP Standard Recommendations (PSR) and Key Standards

PHP Standard Recommendations (PSR) are a set of specifications created by the PHP Framework Interoperability Group (PHP‑FIG) to improve PHP code quality, readability, and maintainability.

PSR comprises about 22 standards covering autoloading, interface definitions, HTTP specifications, coding style, and other core principles.

Understanding these practices as formal PSR standards helps you follow best practices in a consistent and professional manner.

Class Naming

Start with an uppercase letter.

Use CamelCase for multi‑word class names.

class UserController

Method Naming

Start with a lowercase letter.

Use CamelCase for multi‑word method names.

public function getAllUsers()

Some core PSR standards include:

PSR-0: Basic autoloading (deprecated, replaced by PSR-4).

PSR-1: Basic coding standard defining simple, consistent naming conventions for files, classes, and constants.

PSR-2: Coding style guide extending PSR-1 with rules on indentation, braces, and spacing.

PSR-3: Logger interface standardizing a common logging API.

PSR-4: Improved autoloading providing a modern approach to file and namespace organization.

PSR-5: PHPDoc (draft) aiming to standardize documentation comments.

PSR-6: Cache interface for consistent cache storage and retrieval.

PSR-7: HTTP message interface defining request and response objects.

PSR-11: Container interface for dependency injection containers.

PSR-12: Extended coding style guide building on PSR-2 with more details on namespaces, imports, and file structure.

PSR-13: Hypermedia links handling resources.

PSR-14: Event dispatcher for managing application events.

PSR-15: HTTP middleware interface.

PSR-16: Simple cache, a lightweight version of PSR-6.

PSR-17: HTTP factories for creating request and response objects.

PSR-18: HTTP client interface for sending requests and receiving responses.

PSR-19 (draft): PHPDoc standard draft.

PSR-20 (draft): DateTime interface draft.

PSR-21 (draft): Internationalization standard.

PSR-22 (draft): Binary data handling.

PSR-23 (draft): Task scheduler interface.

PSR-24 (draft): Event sourcing for event‑driven architectures.

backend developmentcoding standardsPHPPHP-FIGPSR
php中文网 Courses
Written by

php中文网 Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.