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
Recommended Reading Path
New to PSRs? Follow this order — it builds knowledge progressively:
Foundation (Start Here)
- PSR-1: Basic Coding Standard — The “house rules” for PHP code
- PSR-12: Extended Coding Style — Detailed formatting rules (extends PSR-1)
- PSR-4: Autoloading Standard — How PHP finds your classes automatically
Core Infrastructure
- PSR-3: Logger Interface — Standardized logging across your application
- PSR-11: Container Interface — Dependency injection made interoperable
- PSR-14: Event Dispatcher — Decoupled communication between components
HTTP Stack (Read in Sequence)
- PSR-7: HTTP Message Interfaces — The standard “shape” of HTTP requests and responses
- PSR-17: HTTP Factories — Creating PSR-7 objects without coupling to implementations
- PSR-15: HTTP Handlers and Middleware — Processing HTTP requests through a middleware pipeline
- PSR-18: HTTP Client — Sending HTTP requests the standard way
Data and Caching
- PSR-6: Caching Interface — Full-featured cache pools and items
- PSR-16: Simple Cache — Lightweight key-value caching
Specialized
- PSR-13: Hypermedia Links — Self-documenting REST APIs with HATEOAS
- PSR-20: Clock Interface — Testable time handling
Quick Reference (by PSR Number)
| PSR | Topic | Post |
|---|---|---|
| 1 | Basic Coding Standard | Read |
| 3 | Logger Interface | Read |
| 4 | Autoloading Standard | Read |
| 6 | Caching Interface | Read |
| 7 | HTTP Messages | Read |
| 11 | Container Interface | Read |
| 12 | Extended Coding Style | Read |
| 13 | Hypermedia Links | Read |
| 14 | Event Dispatcher | Read |
| 15 | HTTP Handlers | Read |
| 16 | Simple Cache | Read |
| 17 | HTTP Factories | Read |
| 18 | HTTP Client | Read |
| 20 | Clock | Read |
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 👋