PHP, the backbone of countless web applications, is set to release its latest version, PHP 8.4, on November 21, 2024. This release promises to bring a host of new features, improvements, and changes designed to make the language more powerful and user-friendly for developers.
Let’s dive into what’s new in PHP 8.4 and why it’s worth getting excited about.
Key features that are expected in new PHP 8.4!
Property hooks
One of the most anticipated features of PHP 8.4 is property hooks. This feature allows developers to define custom “get” and “set” behaviors of class properties. Inspired by languages like Kotlin and Swift, property hooks simplify the creation of accessors and mutators, reducing boilerplate code and making the codebase cleaner and more maintainable.
Enhanced array functions
PHP 8.4 introduces several new array functions such as ‘array_find’, ‘array_find_key’, ‘array_any’, and ‘array_all’. These functions make it easier to perform common operations on arrays, providing more expressive and concise ways to handle array data.
Improved DateTime handling
The DateTime class sees significant enhancements with new methods like ‘DateTime(Immutable) : :createFromTimestamp’. These methods offer finer control over date and time manipulation including microsecond precision and easier timestamp conversions.
Advanced string manipulation
String handling in PHP gets a boost with the addition of new functions such as ‘mb_ucfirst’ and ‘md_lcfirst’ for multibyte strings, and ‘mb_trim’,‘mb_ltrim’, and ‘md_rtrim’ for trimming operations. These additions enhance PHP’s ability to handle complex string manipulations more effectively.
Some functions in PHP 8.4 and their default behaviors:
‘mb_trim($string, $characters)’: it trims characters from both ends of a string.
‘mb_ltrim($string, $characters)’: it trims characters from the left side beginning of a string.
‘mb_rtrim($string, $characters)’: it trims characters from the end (right side) of a string.
$characters include several whitespace characters by default. However, not all Unicode characters are included due to storage and compatibility concerns.
HTTP and CURL enhancements
PHP 8.4 introduces new HTTP functions like ‘http_(get|clear)_last_response_headers’, which provide better control over HTTP response headers.
Additionally, ‘curl_version()’ now supports a feature list, giving developers more information about the capabilities of their Curl setup.
Large XML documents can be parsed reliably now
There is a potential issue in the ext/xml PHP extension about the handling of large XML document parsing. The risk of this issue has vanished by including this change in PHP 8.4.
Conflicting modifications in libxmk2 v 2.7.0 unintentionally disrupted large document parsing when using xml_parse() and xml_parse_into_struct() functions, resulting in a parsing error.
Nevertheless, PHP 8.4 introduced a new parser option to handle large XML documents and mitigate parsing errors. It will be a help for developers to parse large XML documents without having to perform complex workarounds.
Deprecations and removals from PHP 8.4
As part of its continuous improvement, PHP 8.4 deprecates certain features to streamline the language and encourage best practices:
Implicitly nullable parameters
These are deprecated to avoid ambiguity and promote explicit nullability in function parameters.
CURLOPT_BINARYTRANSFER option
The Curl option is deprecated, simplifying Curl usage.
Additionally, some extensions are moved from the PHP core to PECL, including the OCI8, PDO-OCI, and IMAP extensions, indicating a shift towards a more modular PHP core.
Syntax and Functionality changes
Open SSL: minimum required version increased to 1.1.
In PHP, Open SSL extension helps with encryption, key exchange, authentication, generic hashing functionality and password hashing to PHP. It uses the Open SSL library to provide its functionalities.
Thus, PHP 8.4 and later versions will use the OpenSSL extension 1.1.1 instead of 1.0.1.
Rounding mode improvements
The ‘round()’ function in PHP 8.4 throws ‘\ValueError’ exceptions for invalid rounding modes, ensuring stricter and more predictable behavior in numerical operations.
Password hashing: default Brypt cost changed from 10 to 12
In PHP 8.4, the cost parameter of the password_default/password_bcrypt algorithm has changed from 10 to 12 to make the passwords more challenging to calculate given the more capable hardware available compared to when the default value was decided.
The change is equivalent to:
password_hash('hunter2', PASSWORD_BCRYPT, ['cost' => 10]); password_hash('hunter2', PASSWORD_BCRYPT, ['cost' => 12]);
Wrapping up
The PHP 8.4 release introduces meaningful language improvements, new capabilities, and refinements that can help developers build and maintain modern web applications more effectively. From cleaner development workflows to improved functionality, the release gives teams several reasons to evaluate their existing PHP environments.
Before upgrading, review your application’s compatibility, dependencies, hosting environment, and custom code to minimize disruption. A well-planned upgrade or migration can help your website or application take advantage of the latest PHP capabilities while maintaining stability and performance.
Skynet Technologies provides custom PHP development services for websites, ecommerce platforms, CMS solutions, enterprise applications, upgrades, migrations, and ongoing maintenance. Our PHP developers can assess your existing environment and recommend an appropriate upgrade or development approach. Share Your PHP Project Requirements with our team to discuss the next step.
