PHP 8.4 Released: What Changed and Why It Matters for Developers
The PHP community has welcomed the long-awaited release — PHP 8.4. The new version brings not only targeted performance improvements but also fundamental changes in syntax that change the approach to writing code. Let's break down the key innovations that every developer should know.
Property Hooks — A Long-Awaited Revolution in Working with Properties
One of the most significant changes is the introduction of property hooks. Now you can define getters and setters directly in the property declaration, without creating separate methods. This makes code cleaner and reduces boilerplate code.
- Inline Getters and Setters: now you can write
public string $name { get => $this->name; set => $this->name = $value; } - Lazy Initialization: a property can be computed only on first access, saving resources.
- Simplified DTOs and Value Objects: data transfer objects become more compact and readable.
Asymmetric Visibility
PHP 8.4 introduces the ability to set different visibility for reading and writing a property. For example, you can make a property public for reading but protected for writing. This solves a long-standing encapsulation problem without creating redundant methods.
- Example:
public private(set) string $title— the property can be read by everyone, but only modified within the class. - Safer: allows stricter control over data mutability.
JIT Compiler Improvements
The development team has significantly improved the JIT (Just-In-Time compiler). In PHP 8.4, it has become more predictable and efficient, especially for long-running processes and API workloads.
- Reduced compilation overhead.
- Improved support for ARM architecture (Apple Silicon, Raspberry Pi).
- Performance gains of up to 10-15% in synthetic benchmarks.
New Syntax and Deprecations
The release also includes syntactic sugar and the removal of outdated functions.
- Improved
array_find: now you can writearray_find($users, fn($u) => $u->active)— finds the first matching element. - Removal of deprecated functions:
mysqliwithout prepared statements and a number of rarely used constants have been removed from the core. - New types:
trueandfalsehave been added as standalone types for strict typing.
What Does This Mean for Developers?
PHP 8.4 is a step towards more modern and safer code. Property hooks and asymmetric visibility reduce the amount of boilerplate code, while the improved JIT makes PHP faster without changing code. We recommend starting to test your projects' compatibility with the new version now, especially if you use frameworks like Laravel or Symfony — they have already released updates to support PHP 8.4.
Stay tuned to PythonLib for news — we will continue to break down the technical details of the new release and write migration guides.