PHP 8.4: New Features Overview
Property hooks, asymmetric visibility and more – the key new features in PHP 8.4.
PHP 8.4 – Key New Features
PHP 8.4 brings exciting new features that significantly improve the developer experience. Here's an overview of the most important changes.
Property Hooks
One of the biggest features in PHP 8.4 are Property Hooks. They allow you to define getter and setter logic directly in the property declaration:
class User {
public string $name {
set => strtolower($value);
get => ucfirst($this->name);
}
}This eliminates a lot of boilerplate code and makes classes much more readable.
Asymmetric Visibility
With asymmetric visibility, properties can have different access levels for reading and writing:
class Product {
public private(set) string $name;
public protected(set) float $price;
}$name can be read from outside but only set within the class.
New Array Functions
PHP 8.4 finally adds array_find(), array_find_key(), array_any() and array_all():
$users = [['name' => 'Sven', 'active' => true], ['name' => 'Max', 'active' => false]];
$found = array_find($users, fn($u) => $u['name'] === 'Sven');
$hasActive = array_any($users, fn($u) => $u['active']);
Conclusion
PHP 8.4 is a solid release that brings significant comfort improvements, especially when working with classes and properties. The new array functions were long overdue.
If you're already on PHP 8.3, you should plan the upgrade – most changes are backwards compatible.