PHP 8.4: Release Date and Features, April 2024

Doğan Uçar
6 min readApr 17, 2024

--

PHP 8.4 is poised to introduce a range of new features and updates that are designed to improve security, enhance functionality, and provide developers with new tools to manage and process data more efficiently. PHP 8.4 is expected to be released in November 2024, according to the Preparation Tasks.

Here’s a overview at what to expect, and, what I think is important — divided into specific areas of enhancement:

TL;DR: So far, the new version 8.4 of PHP includes the cost increase of bcrypt, adds new rounding options for round(), adds support for large XML file parsing, introduces independent options for JIT, is more restrict with implicit nullable arguments, enhances HTTP and DateTime methods and classes, adds methods to have a better support for multibyte strings, supports HTML5 and deprecates oci8 for Oracle databases and IMAP.

Increased Bcrypt Cost

In PHP 8.4, the default bcrypt cost parameter, which controls the computational expense of hashing passwords, will be increased to 12. This change makes the hashing process slightly slower but significantly more secure against brute force attacks. As computational power increases, adjusting the bcrypt cost ensures that password hashing remains a robust defense mechanism. This update reflects PHP’s ongoing commitment to security best practices.

from PHP 8.3 to PHP 8.4

New Rounding Options in the round() Function

The round() function will now include additional rounding modes such as PHP_ROUND_CEILING, PHP_ROUND_FLOOR, PHP_ROUND_AWAY_FROM_ZERO, and PHP_ROUND_TOWARD_ZERO, offering developers more precise control over numerical operations.

Enhanced XML Document Parsing

PHP 8.4 addresses issues with parsing large XML documents through the introduction of a new parser option, XML_OPTION_PARSE_HUGE. This option ensures reliable parsing of large XML files, avoiding the errors that were previously encountered with large data sets. This improvement is particularly valuable for applications that need to handle extensive XML data efficiently.

Independent IR Framework for JIT in PHP 8.4

The new version introduces another approach for the Just-In-Time (JIT) compilation with a new implementation based on an Independent IR Framework. This new JIT framework aims to consolidate the various back-ends, facilitating IR construction and enabling machine-independent optimizations. This design is particularly appealing as it integrates smoothly with the existing PHP codebase, causing minimal disruptions. It also opens doors for future enhancements and collaborations with external experts in compiler technology, potentially boosting PHP’s performance in running complex applications.

Implicit Nullable

In PHP 8.4, a significant deprecation affects implicitly nullable parameter declarations, marking a notable change that could trigger deprecation notices in legacy PHP applications. This change is part of PHP’s ongoing efforts to refine its type system, which has seen numerous enhancements since PHP 5.1.

Historically, PHP has allowed developers to declare a parameter type with a default value of null. This practice made the parameter type implicitly nullable, regardless of whether null was explicitly allowed as a type. However, with PHP 8.4, this approach is deprecated in favor of more explicit type declarations:

function doStuff(string $test = null) {}

test('HelloWorld'); // valid
test(null); // valid

The recommended approach to handle this deprecation is straightforward and compatible with PHP 7.1 and later versions. Developers are encouraged to explicitly declare nullable types using the ‘?’ prefix to enhance clarity and maintain compatibility with PHP’s evolving type system. This adjustment ensures that PHP’s type declarations remain robust and clear, minimizing potential misunderstandings in code about what types are permissible.

HTTP Handling Enhancements

Several older features and extensions are being deprecated or moved to PECL, signaling PHP’s move towards more efficient and secure practices. Notable changes include the deprecation of CURLOPT_BINARYTRANSFER and the movement of extensions like Pspell and IMAP to PECL.

In an effort to modernize and clarify HTTP header management in PHP scripts, PHP 8.4 introduces two new functions related to the HTTP wrapper:

  • http_get_last_response_headers(): This function retrieves the headers from the last HTTP response received by the current script, effectively replacing the need to access the $http_response_header variable directly. This enhances readability and reduces the confusion associated with the “magic” nature of this historically populated variable.
  • http_clear_last_response_headers(): Clears the headers retrieved by the aforementioned function, allowing for better control and management of HTTP header data within an application’s lifecycle.

These functions aim to simplify the handling of HTTP headers by providing a more structured and intuitive approach, moving away from the indirect and somewhat opaque use of a locally scoped variable. This change not only makes code easier to understand and maintain but also improves compatibility with IDEs and static analyzers by eliminating the need to handle a special variable that doesn’t behave like typical superglobals.

Did you know that Keestash is built with PHP? Check out the repository or sign up to use Keestash!

Keestash Logo

Enhanced Date and Time Handling in PHP 8.4

PHP 8.4 makes a significant change to the DateTime and DateTimeImmutable classes, making them more precise and versatile for developers working with date and time data. Here are the key features introduced:

The DateTime and DateTimeImmutable classes now include getMicrosecond and setMicrosecond methods. These methods are particularly useful for applications that require high-resolution time measurement, such as logging, simulation, or financial applications, where more precise time stamps are crucial.

These enhancements not only increase the precision of the DateTime functionalities but also simplify the management of time data by allowing direct access to microseconds. This can be particularly useful in contexts where time calculations need to include very small intervals, or when time data comes from sources that provide high granularity.

The addition of these methods supports more accurate time stamping and could be instrumental in fields that rely on precise time measurements. Moreover, it aligns PHP’s date and time capabilities more closely with those found in other high-level programming languages, enhancing PHP’s utility for scientific and financial programming.

Multibyte String Functions

To better handle multibyte characters in string operations, PHP 8.4 introduces three new functions in the mbstring extension:

  • mb_trim(): Trims whitespace and other predefined characters from both ends of a string.
  • mb_ltrim(): Removes characters from the beginning of a string.
  • mb_rtrim(): Eliminates characters from the end of a string.

These functions are essential for applications dealing with languages that use multibyte character encodings, ensuring that string manipulation functions do not inadvertently remove or alter unintended characters.

Support for HTML5 Document Parsing

A significant update is the introduction of the DOM\HTMLDocument class, which allows for parsing and serializing HTML5 documents. This is a step up from the current HTML4 capabilities, aligning PHP more closely with modern web standards.

PHP 8.4 deprecates oci8 and IMAP extensions

The oci8 and pdo_oci extensions, which enable Oracle database functionality in PHP, have been shifted out of the PHP core and moved to PECL, now known as oci8 and pdo_oci respectively. These extensions have historically relied on proprietary libraries from Oracle, a commercial vendor, which necessitated specific efforts for integration and maintenance. Over time, these extensions have accumulated a number of unresolved bugs. Due to this and further challenges and the reliance on third-party proprietary libraries, the decision was made to relocate oci8 and pdo_oci to PECL, removing them from the core PHP distribution.

The IMAP extension in PHP, which facilitates operations on mailboxes using the IMAP protocol, has encountered several challenges that have influenced its transition out of the PHP core and into PECL. Notably, the underlying C library that the extension relies on has not been updated since 2018, which raises concerns about the extension’s current relevance and efficiency.

In response to this, PHP 8.4 no longer includes the IMAP extension as part of its core distribution, and it has been moved to PECL. While it is still possible to install the IMAP extension from PECL, developers are encouraged to consider migrating to alternative libraries that may offer better support, security, and functionality.

PHP evolves

PHP is continuously evolving, adapting to new technological demands and security standards, which is a thrilling development for anyone involved in web development. As a freelance PHP specialist, I am particularly excited about these advancements, as they bring enhanced capabilities and improved performance to the projects I work on. Staying abreast of these changes allows me to offer top-tier development services, ensuring that my clients’ applications are both robust and cutting-edge. If you’re looking to harness the latest features of PHP or need help navigating the complexities of upgrading to PHP 8.4, I’m just a message away. Reach out to discuss how we can elevate your PHP applications together.

Get in Touch

Originally posted on my blog: https://www.dogan-ucar.de/php-8-4-release-date-and-features-april-2024/

--

--

Doğan Uçar
Doğan Uçar

Written by Doğan Uçar

Software Engineer, PHP/Laminas (Zend), Backend, Cloud, Freelancer & CEO, Open Source Contributor

No responses yet