A grown PHP monolith can rarely be replaced in one big leap. Legacy PHP code can, however, be modernized in a controlled way if you identify seams, write characterization tests and gradually wrap the old code using the Strangler Fig pattern instead of replacing it in one risky rewrite.
The decorator pattern solves a problem that plain inheritance cannot cleanly solve: combining several independent additional behaviors, for example logging, caching and validation, flexibly and in any order, without building a separate subclass for every combination. This article shows how the decorator pattern in PHP preserves interface conformance and when it is preferable to inflating inheritance hierarchies.
strlen() counts bytes, not characters, and returns wrong values for umlauts and Unicode characters almost every time. This guide explains how UTF-8 encoding works, why mb_ functions are essential for multibyte strings, and how truncation, sorting, escaping and regular expressions with umlauts work reliably in PHP 8.4.
DateTime objects can be changed after creation, and that is exactly what produces hard-to-find bugs in larger codebases. DateTimeImmutable solves this problem structurally by having every method return a new instance instead of changing the existing object. This article shows, with real PHP 8.4 code, how DateTimeImmutable, DateTimeZone and DateInterval work together, and how existing DateTime code can be migrated.
Anonymous classes let you define a fully fledged class right at the point of use with new class(), without assigning a global name. Used correctly, they replace mocking libraries in tests, avoid unnecessary class names for one off implementations, and let you write more compact yet type safe code.
A pure function always returns the same result for the same arguments and changes nothing outside its own return value. This principle of referential transparency makes PHP code predictable, easy to test and parallelizable, without any extra framework or new language syntax.
Process parallelization with pcntl lets PHP CLI scripts create real operating system processes and actually run CPU-bound work concurrently across multiple cores. Anyone who masters pcntl_fork, pcntl_wait and signal handling can build worker pools that drain queues, process batch jobs and shut down cleanly instead of leaving zombie processes behind.
Magic Methods like __get, __call and __invoke look elegant at first glance, since they let PHP react to undefined properties and methods. Used carelessly, though, they produce code that neither IDE autocompletion nor PHPStan can understand anymore, significantly complicating debugging and maintenance.
Long before PHP had Reflection or attributes, it already offered a way to treat function names and variable names themselves as values at runtime. Variable functions and variable variables are the oldest form of metaprogramming in PHP, powerful and risky at the same time, and still the foundation of many dynamic dispatchers today.
Unlike Elixir or the proposed JavaScript feature, PHP has no native pipe operator. A single small pipe() function still recreates the same readable data flow in PHP 8.4, left to right instead of deeply nested function calls.