PHP Articles
18 articles found
Browse by topic: PHP · Infrastructure · Database · AI & LLMs · TypeScript · Quality Assurance
PHP Exception Best Practices: Hard Rules, Project-Level Hierarchies, and Modern 8.4 Patterns
Simple hard rules for when to throw RuntimeException vs LogicException vs InvalidArgumentException, when to create project-level exceptions, how to structure them with typed properties and static factory methods, and how to log them properly with Monolog. Python and TypeScript get a cursory treatment at the end.
OpenAPI and Automatic Code Generation: Define Once, Generate Everywhere
How OpenAPI specifications let you define your API once and automatically generate type-safe client SDKs, server stubs, and models in PHP, TypeScript, Python, and dozens of other languages.
Using PHPStan to Enforce Project-Level Rules
Learn how to write custom PHPStan rules to enforce performance, architectural, and testing standards across your entire codebase. Includes real-world examples and multi-language comparisons.
Caching vs Memoization: Choosing the Right Optimization Strategy
Deep dive into caching and memoization strategies, their differences, use cases, anti-patterns, and practical implementation tips across programming languages.
Reusable OpenAPI Classes: Eliminating Boilerplate in PHP API Documentation
A worked example of the DRY principle applied to Symfony API documentation: wrap swagger-php OpenAPI attributes in your own reusable response, parameter, and security classes so a single change updates every endpoint that uses it.
PHP Stream Wrappers: Mastering I/O Abstraction and Custom Protocols
How PHP treats files, URLs, compressed data, and custom protocols through the same handful of functions, and when writing your own wrapper is worth the extra code
How Lenient Regex Patterns Explode Your Code Paths
Why optional regex patterns create exponential complexity and how strict validation reduces maintenance burden through fail-fast principles.
Dependency Inversion, Final Classes, and Pragmatic Testing in PHP 8.4
Why final classes push dependency inversion toward composition over inheritance, and how the Detroit/London testing split resolves into a simpler rule for when to reach for a mock.
Defensive Programming Principles: YAGNI, Invalid States, and Domain Purity
A practical look at three techniques - YAGNI, type-driven invalid-state prevention, and domain object purity - for cutting whole categories of bugs out of PHP and TypeScript codebases before they can exist.
Fail Fast Programming: Why Your Code Should Crash Spectacularly
A practical look at fail-fast programming in PHP, TypeScript, Bash, and Ansible - writing high-trust code that fails early, clearly, and at the exact point of deviation from expectations.
Early Return Patterns: Your Code's Best Exit Strategy
Master guard clauses and early return patterns across PHP, TypeScript, Bash, and Ansible to write cleaner, more maintainable code with reduced cognitive complexity
Mocking in Tests: Like Hot Sauce - A Little Goes a Long Way
Learn when to mock and when not to mock in unit tests. Discover why over-mocking creates brittle, unmaintainable tests and how to write better tests with minimal mocking using TypeScript, Vitest, and PHPUnit.
PHP Magic Constants for Maintainable Logging Systems
Master PHP magic constants (__FILE__, __METHOD__, __CLASS__, etc.) to build contextual logging systems with Monolog and PSR-3 that automatically track execution flow and debugging information.
PHP-QA-CI: A Comprehensive Quality Assurance Pipeline in a Single Dependency
LTS PHP-QA-CI provides a complete, production-ready QA pipeline with a full suite of integrated tools through a single Composer dependency, covering configuration, customisation, and CI/CD integration strategies.
PHP PER: The Evolution Beyond PSR-12 Coding Standards
Understanding PHP Evolving Recommendations (PER), how to enforce them with QA tools, and why PER Coding Style looks like the direction PHP standards are heading.
Managing Legacy PHP: From Technical Debt to Modern Architecture
Strategies for modernising legacy PHP codebases and managing technical debt effectively
High-Performance PHP: Optimisation Strategies
OPcache tuning, connection pooling, multi-level caching and async job queues for PHP applications under real load
Building Scalable Backend APIs with Modern PHP
Comprehensive guide to building scalable, maintainable PHP APIs using modern architecture patterns