PHP 8.4 Released: What Changed and Why It Matters
The developer community has welcomed the long-awaited release of PHP 8.4 — a new major version of one of the most popular web programming languages. The update brings a number of significant improvements, including long-awaited property hooks, asymmetric visibility, and substantial performance optimization. Let's break down the key changes every PHP developer should know.
1. Property Hooks
The most notable innovation is the ability to define getters and setters directly in the property declaration of a class without writing separate methods. This radically simplifies working with computed or validated fields.
class User{ public string $name { set => $this->name = trim($value); get => ucfirst($this->name); }}Previously, such logic required writing separate getName() and setName() methods. Property hooks make the code cleaner and more readable.
2. Asymmetric Visibility
Now you can set different access levels for reading and writing a property. For example, public reading but protected writing:
class Post{ public private(set) string $title;}This eliminates the need to create getters and setters solely for access control, while preserving encapsulation.
3. Improved JIT and Performance
In PHP 8.4, the JIT (Just-In-Time) compiler has been significantly reworked. Core developers improved the heuristics for compilation decisions and reduced overhead when executing hot code paths. According to preliminary tests, performance gains in synthetic benchmarks range from 10% to 25% compared to PHP 8.3.
- Faster execution of loops and recursive functions
- Improved handling of large arrays
- Memory consumption reduction in JIT mode by up to 15%
4. New Syntax: Array Destructuring with Types
Added the ability to specify types when destructuring arrays:
[$name, $age] = ['Ivan', 30]; // was[ string $name, int $age ] = ['Ivan', 30]; // nowThis improves static analysis and makes the code self-documenting.
5. Changes in the Standard Library
- New functions:
array_find(),array_find_key(),array_any(), andarray_all()— for more concise array handling. - PCRE2 update: the regular expression library has been updated to version 10.44, fixing several rare bugs.
- Deprecated functions:
session_set_cookie_params()(in favor ofini_set()) and several internal functions have been deprecated.
6. Deprecations
In PHP 8.4, the following have been marked as deprecated:
- Changing the return type via
#[\\ReturnTypeWillChange]— now requires an explicit declaration. - Calling
isset()on non-arrays (e.g.