PHP Articles

18 articles found

Browse by topic: PHP · Infrastructure · Database · AI & LLMs · TypeScript · Quality Assurance

PHP

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.

15 April 2026·18 min read
PHP

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.

24 March 2026·20 min read
PHP

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.

10 November 2025·12 min read
PHP

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.

6 October 2025·10 min read
PHP

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.

30 September 2025·12 min read
PHP

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

26 September 2025·9 min read
PHP

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.

26 September 2025·5 min read
PHP

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.

11 August 2025·18 min read
PHP

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.

7 August 2025·14 min read
PHP

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.

4 August 2025·12 min read
PHP

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

31 July 2025·9 min read
PHP

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.

30 July 2025·10 min read
PHP

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.

28 July 2025·12 min read
PHP

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.

25 July 2025·15 min read
PHP

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.

24 July 2025·12 min read
PHP

Managing Legacy PHP: From Technical Debt to Modern Architecture

Strategies for modernising legacy PHP codebases and managing technical debt effectively

15 January 2025·14 min read
PHP

High-Performance PHP: Optimisation Strategies

OPcache tuning, connection pooling, multi-level caching and async job queues for PHP applications under real load

28 December 2024·12 min read
PHP

Building Scalable Backend APIs with Modern PHP

Comprehensive guide to building scalable, maintainable PHP APIs using modern architecture patterns

15 December 2024·16 min read