We are thrilled to announce that after a year of hard work, dedication, and collaboration, PHP 8.4 is officially here!
Thanks to the tireless efforts of the PHP Foundation members, the core PHP development team, and an incredible community of contributors, this upcoming version brings major new features and syntax, performance and security enhancements, and a healthy amount of deprecations.
The PHP Foundation financially supports ten PHP core developers. The PHP Foundation members, along with a total of 115 contributors, have made over 2,600 commits since PHP 8.3 until PHP 8.4.0 release.
PHP 8.4 includes changes from 36 RFCs. There have also been numerous mailing list discussions and RFCs that were withdrawn, declined, or are still under discussion.
Since PHP 8.0, PHP 8.4 received the highest number of RFCs, and PHP 8.4 brings the changes such as property hooks and asymmetric visibility that received significant community involvement and refinement.
PHP 8.4 brings numerous new features and improvements to PHP. We covered some of them in our previous post as well, but they are mentioned here as well, for more complete picture.
As we also covered in PHP Core Roundup #19, Property Hooks and Asymmetric Visibility are two of the highlighted features in PHP 8.4
In PHP 8.4, it is possible for a class to declare class properties with "hooks", that get executed when the property is accessed or set, and the hooks can access the object context.
Property hooks open up a wide range of use cases that allow classes to declare virtual properties that enable expressive and intuitive APIs, make code readable and simple and avoid boilerplate code.
class User {
public string $emailAddress {
set {
if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
throw new ValueError('emailAddress property must be a valid email address');
}
$this->emailAddress = $value;
}
}
}
$user = new User();
$user->emailAddress = 'test@example.com'; // Allowed
$user->emailAddress = 'not an email address'; // Throws ValueError
Larry Garfield wrote in PHP 8.4: How Property Hooks Happened about how he and Ilija Tovilo 💜 brought Property Hooks to PHP.
PHP 8.4 introduces asymmetric visibility, allowing different access levels for getting and setting class properties. This feature is useful when you want to expose a property for reading but not writing.
class User {
public private(set) int $userId;
public function __construct() { $this->userId = 42; }
}
$user = new User();
echo $user->userId; // 42
$user->userId = 16; // Error: Cannot modify private(set) property
PHP 8.4 brings support for Lazy Objects. Using the Reflection API, it is possible to create class instances in PHP 8.4 that they are initialized only if needed.
The Lazy Objects documentation provides detailed examples and use cases.
PHP 8.4 upgrades the DOM extension with HTML5-compliant parsing. The new Dom\HTMLDocument
and Dom\XMLDocument
classes replace libxml2, which previously lacked HTML5 support. These updates improve DOM spec compliance and add features like CSS selector support.
BcMath\Number
classThe BCMath extension now includes the BcMath\Number
class, enabling operator overloading for arithmetic operations.
use BcMath\Number;
$num1 = new Number('22');
$num2 = new Number('7');
$num3 = new Number('100');
$result = ($num1 / $num2) + $num1 - $num2;
echo $result; // 18.1428571428
You can now use standard operators (+
, -
, /
) with BcMath\Number
objects, which also support all bc*
functions.
These objects are immutable and implement the Stringable
interface, so they can be used in string contexts like echo $num
.
array_find
, array_find_key
, array_any
, and array_all
bcdivmod
, bcround
, bcceil
, and bcfloor
mb_trim
, mb_ltrim
, and mb_rtrim
mb_ucfirst
and mb_lcfirst
grapheme_str_split
fpow
http_get_last_response_headers
and http_clear_last_response_headers
The PDO Driver-specific subclasses RFC is implemented in PHP 8.4. Previously, it was voted for PHP 8.3 but was not implemented in PHP 8.3 before its feature-freeze.
PHP 8.4 now adds Pdo\Mysql
, Pdo\Pgsql
, Pdo\Sqlite
, Pdo\DbLib
, and Pdo\Firebird
classes that extend the PDO
class. Driver-specific methods, properties, and constants are now available in the driver-specific subclass. Driver-specific sub classes also allow APIs to be more expressive and restrictive by allowing the functions and methods only to accept/return driver-specific sub-classes.
AEGIS-128L
and AEGIS256
support in Sodium extensionAEGIS is an AES-based family of authenticated encryption algorithms that is faster than AES-GCM. The Sodium extension in PHP 8.4 supports AEGIS-128L
and AEGIS256
encryption algorithms if the Sodium extension is compiled with libsodium
1.0.19 or later.
Apart from the new features, PHP 8.4 also updates several underlying dependencies and datasets, as well as unbundling three extensions:
mod_php
), PHP 8.4 drops support for the EOL Apache 2.0 and 2.2 series. The minimum required Apache version is now 2.4.IMAP, Pspell, OCI8, and PDO_OCI8 extensions are unbundled from the PHP core, and are now available as PECL extensions, for which PIE might help to install easily.
PHP 8.4 also brings a minor, yet very overdue change to the PHP icon on Windows executables:
Old Icon | New Icon |
PHP 8.4 is the first major new PHP releases since the adoption of the new PHP maintenance policy. PHP 8.4, along with all current active PHP versions, will receive two years of active support and two years of security fixes.
What this means is that PHP 8.4 will receive bug fixes until the end of 2026 and security fixes until the end of 2028.
We just announced the pre-release of PIE - PHP Installer for Extensions. PIE will significantly improve the workflow of downloading and compiling PHP extensions.
PHP 8.5 (in the master
branch) is currently under active development, and we already have RFCs such as Support Closures in constant expressions in voting phase, and Add RFC3986 and WHATWG compliant URI parsing support under discussion.
PHP 8.4.1 is now a tagged release on PHP's GitHub repository.
Compiled binaries and container images are available for:
At The PHP Foundation, we support, promote, and advance the PHP language. We financially support ten PHP core developers to contribute to the PHP project. You can help support PHP Foundation on OpenCollective or via GitHub Sponsors.
A big thanks to all our sponsors — PHP Foundation is all of us!
Follow us on Twitter/X @ThePHPF, Mastodon, LinkedIn, and Bluesky to get the latest updates from the Foundation.
💜️ 🐘
PHP Roundup is prepared by Ayesh Karunaratne from PHP.Watch, a source for PHP News, Articles, Upcoming Changes, and more.