What's New in PHP 8.4
Property hooks, asymmetric visibility, new array helpers, and an HTML5-compliant DOM API — a tour of the headline changes in PHP 8.4.
PHP 8.4 (released November 2024) is one of the more substantial releases in the PHP 8 series, adding several long-requested language features alongside the usual performance and deprecation work.
Property hooks
Properties can now define get and set behavior directly, without
a separate getter/setter method pair:
class User
{
public string $name {
set (string $value) {
$this->name = ucfirst($value);
}
}
}
This removes a huge amount of boilerplate in classes that previously
needed __get/__set magic methods or explicit accessor methods
just to validate or normalize a value on assignment.
Asymmetric visibility
A property can now have a different visibility for reads than for writes — most commonly, publicly readable but only privately writable:
class Order
{
public private(set) string $status = 'pending';
}
Previously this required a private property plus a public read-only accessor method just to prevent external code from mutating state it shouldn't touch.
New array functions
array_find(), array_any(), and array_all() land in 8.4, closing
a long-standing gap versus array_filter() + manual iteration:
$hasAdmin = array_any($users, fn ($user) => $user->isAdmin());
Dom\HTMLDocument
A new Dom\HTMLDocument class provides spec-compliant HTML5 parsing
and serialization, addressing long-standing quirks in the legacy
DOMDocument class (which predates HTML5 and mishandles many modern
HTML documents).
Deprecations to watch for
Implicitly nullable parameter types (e.g. function f(int $x = null)
without an explicit ?int) are now deprecated — an explicit ?int
is required going forward. Codebases upgrading to 8.4 should expect
deprecation notices here and plan to add the explicit ? rather than
suppress the warning.