New PHP 8.4 Release: What Changed and Why You Should Upgrade
The developer community has welcomed the long-awaited PHP 8.4 release. This version brings not only targeted improvements but also several fundamental syntax changes that alter the approach to writing code. If you follow the web development ecosystem, this release is an important step forward. Let's break down the main innovations.
Property Hooks: Long-Awaited Conciseness
One of the most discussed innovations is property hooks. Previously, to add logic when getting or setting a property value, you had to write getters and setters (methods). Now this can be done directly in the property declaration, reducing boilerplate code.
- Example: Instead of
getFullName()andsetFullName()methods, you writepublic string $fullName { get => ...; set => ...; }. - Benefit: Code becomes more readable and closer to modern languages (Kotlin, C#).
- Flexibility: Hooks can be overridden in child classes, simplifying work with inheritance.
Asymmetric Visibility
Another important innovation is the ability to set different access levels for reading and writing a property. Previously, this required workarounds or separate methods.
- Syntax:
public private(set) string $name;— the property can be read from anywhere, but only modified inside the class. - Use case: Ideal for value objects and DTOs, where it's important to protect data from external modification while keeping it readable.
Type and Performance Improvements
PHP developers continue to strengthen the type system and optimize the engine.
- New types: Added support for
EXITas a type for functions that interrupt execution (exit, die). This improves the accuracy of static analysis. - JIT (Just-In-Time Compiler): Significantly improved. In PHP 8.4, JIT has become smarter: it better optimizes "heavy" loops and mathematical operations, providing a performance boost of up to 10-15% in benchmarks.
- Garbage Collector: The garbage collection mechanism has been reworked. The new algorithm handles cyclic references more efficiently, reducing memory consumption in long-running processes (e.g., queue workers).
Other Notable Changes
In addition to the major innovations, the release includes many small but useful improvements:
- BC Math: New functions added for working with arbitrary precision numbers.
- curl: Updated protocol support and improved error handling.
- Deprecations: Some outdated functions (e.g.,
mysqli_ping) have been marked as deprecated — prepare for their removal in PHP 9.0.
Should You Upgrade?
If you use a modern stack (Laravel, Symfony) — upgrading to PHP 8.4 is recommended. Property hooks and asymmetric visibility will significantly simplify writing clean code. For older projects, check the compatibility of your dependencies, but overall migration from PHP 8.3 will be painless.