Are you tired of wrestling with inconsistent PHP codebases or struggling to make different packages work together? You’re not alone! In this series, we’ll explore how PHP-FIG’s PSR standards can transform your development experience.

What is PHP-FIG?

PHP-FIG is a group of PHP project representatives working together to advance the PHP ecosystem. Their primary contribution is the PSR system, which defines coding standards and interfaces that enable better interoperability between PHP packages and frameworks.

Why PSRs Matter

PSRs solve several critical challenges in PHP development:

  • Code Consistency: Standardized coding styles make code more readable
  • Interoperability: Common interfaces allow different packages to work together seamlessly
  • Best Practices: Established patterns improve code quality and maintainability

New to PSRs? Follow this order — it builds knowledge progressively:

Foundation (Start Here)

  1. PSR-1: Basic Coding Standard — The “house rules” for PHP code
  2. PSR-12: Extended Coding Style — Detailed formatting rules (extends PSR-1)
  3. PSR-4: Autoloading Standard — How PHP finds your classes automatically

Core Infrastructure

  1. PSR-3: Logger Interface — Standardized logging across your application
  2. PSR-11: Container Interface — Dependency injection made interoperable
  3. PSR-14: Event Dispatcher — Decoupled communication between components

HTTP Stack (Read in Sequence)

  1. PSR-7: HTTP Message Interfaces — The standard “shape” of HTTP requests and responses
  2. PSR-17: HTTP Factories — Creating PSR-7 objects without coupling to implementations
  3. PSR-15: HTTP Handlers and Middleware — Processing HTTP requests through a middleware pipeline
  4. PSR-18: HTTP Client — Sending HTTP requests the standard way

Data and Caching

  1. PSR-6: Caching Interface — Full-featured cache pools and items
  2. PSR-16: Simple Cache — Lightweight key-value caching

Specialized

  1. PSR-13: Hypermedia Links — Self-documenting REST APIs with HATEOAS
  2. PSR-20: Clock Interface — Testable time handling

Quick Reference (by PSR Number)

PSRTopicPost
1Basic Coding StandardRead
3Logger InterfaceRead
4Autoloading StandardRead
6Caching InterfaceRead
7HTTP MessagesRead
11Container InterfaceRead
12Extended Coding StyleRead
13Hypermedia LinksRead
14Event DispatcherRead
15HTTP HandlersRead
16Simple CacheRead
17HTTP FactoriesRead
18HTTP ClientRead
20ClockRead

Practical Learning

Each post includes:

  • A relatable analogy explaining what the standard solves
  • The actual PSR interface with commentary
  • A working implementation from our blog API companion project
  • Common mistakes with before/after fixes
  • Framework integration examples (Laravel, Symfony, Slim)
  • A “Try It Yourself” section with exact commands to run

Getting Started

To follow along, clone our companion repository — a blog API that uses all 14 PSRs:

git clone https://github.com/jonesrussell/php-fig-guide.git
cd php-fig-guide
composer install

The blog API demonstrates every PSR in a real project context. Each PSR has:

  • Implementation code under src/
  • PHPUnit tests under tests/
# Run all tests
composer test

# Run tests for a specific PSR
composer test -- --filter=PSR7

# Check coding standards (PSR-1 + PSR-12)
composer check-style

Resources

Baamaapii 👋