From optimized execution times and new syntax options to improved type safety, the new PHP version 8.4 offers modern tools that simplify developers’ work while simultaneously improving the quality of the code. The following presents the most exciting functions and their practical advantages for developers’ everyday work.
Hostpoint customers who want to update their PHP version to 8.4 can do this very easily on their own via the Hostpoint Control Panel. Instructions can be found here.
Property hooks – more efficient read and write access for classes
Property hooks celebrate their debut in PHP 8.4. They allow developers to bind individual logic directly to class properties without having to write separate getter and setter methods. Until now, such tasks had to be solved either via manually implemented methods or using “magic methods” such as __get()
and __set()
. But both approaches were cumbersome and frequently resulted in unclear code.
Thanks to property hooks, the code base is now much clearer. Developers can define a username
property, for example, that is automatically generated from the values of firstName
and lastName
– without additional methods. It is also possible to configure properties with asymmetric visibility – for example, publicly readable but only writable within the class.
This innovation not only saves time, but also significantly improves the maintainability of the code. Functions such as automatic validations or read-only/write-only properties can now be implemented more elegantly and efficiently.
Instantiation without parentheses – clear syntax for better readability
PHP 8.4 introduces a practical syntax change: the ability to call methods directly on newly instantiated classes without the need for additional parentheses.
Previously, the “new” instantiation had to be enclosed in parentheses, such as here:
(new MyClass())->myMethod();
With the new update, it is sufficient to call the method directly:
new MyClass()->myMethod();
This change not only reduces the number of characters in the code but also improves its readability. Especially in complex projects with long method chains, this simplification provides a clearer structure and minimizes errors that could arise from superfluous parentheses.
Dom HTML5 parser – improved processing of HTML5
PHP 8.4 introduces the new class DOM\HTMLDocument, which is based on the modern Lexbor library and natively supports HTML5 documents. In contrast, the existing \DOMDocument class still uses the libxml library, which can only handle HTML up to version 4.01.
Thanks to Lexbor, modern HTML5 elements such as <article>
, <section>
or <video>
can be processed efficiently and directly in PHP. This enables better compatibility with current HTML5 standards and simplifies the processing of complex static HTML documents.
New array functions simplify data processing
PHP 8.4 expands the ability to work with arrays with several new features:
-
array_find()
:
finds the first element that satisfies a specific condition. -
array_find_key()
:
returns the key of the first matching element. -
array_any()
:
checks whether at least one element fulfills the condition. -
array_all()
:
checks whether all elements fulfill a condition.
Before this update, developers had to write complex loops or combinations of functions such as array_filter()
and foreach
to perform similar tasks. These approaches were often laborious and hard to read.
With the new functions, the code is not only shorter, but also more readable. Here’s an example for array_find()
:
$array = ["apple", "banana", "cherry"];
$result = array_find(
$array,
fn(string $item) => strlen($item) > 5
); // Result: "banana"
These features make working with arrays much easier, improve readability and shorten development time. Particularly in data-intensive applications, the new functions offer noticeable benefits in terms of efficiency and performance.
Just-in-time (JIT) compiler for better performance
The just-in-time (JIT) compiler was first introduced in PHP 8.0 and translates PHP code directly into machine code, significantly reducing execution times. Before the introduction of JIT, PHP code was fully interpreted, which often led to performance issues with computationally intensive applications such as complex calculations or large data processing operations.
With PHP 8.4, the JIT compiler is now even more powerful, particularly for online shops, data analysis systems or tools for machine learning. This enables developers to design demanding applications more efficiently without having to resort to external optimizations.
An overview of all the new features in PHP 8.4 can also be found here.
Backward compatibility and migration tips
There are a lot of advantages to updating to PHP 8.4, but it does require thorough preparation to avoid potential compatibility issues. Here are some recommendations and best practices to ensure a smooth migration:
-
Perform a compatibility check:
ensure that your application and all libraries that you use are compatible with PHP 8.4. Check the documentation of your dependencies, as outdated or unmaintained libraries may no longer work with the new PHP version. -
Use the testing environment:
for starters, perform the update in a staging or test environment to identify and correct errors within a secure context. This way you can ensure that the new PHP version will interact smoothly with your application. -
Run automated tests:
use automated testing (unit tests, integration tests, etc.) to ensure that all features of your application are working as expected. Also test the new array functions and property hooks to ensure that they do not affect any existing processes. -
Pay attention to outdated functions and warnings:
PHP 8.4 introduces some new deprecation warnings (notes regarding outdated functions) that could become errors in the future PHP 9 version. Take advantage of this opportunity to identify deprecated functions and adapt the code accordingly. -
Hostpoint customers benefit from flexible PHP versions:
Hostpoint customers can easily enable PHP 8.4 and go back to the previous version if needed. This flexibility is particularly helpful for testing the update step-by-step and making adjustments.
These steps make the migration to PHP 8.4 safe and efficient. A careful plan can help you tap the full potential of the new PHP version without compromising stability and compatibility. Hostpoint is always happy to assist you with any questions you may have regarding migration.
Fazit
PHP 8.4 brings even greater flexibility to the development of high-performance web applications. The new features and performance optimizations provide developers with additional tools to implement complex requirements without sacrificing efficiency.
An additional advantage: support for PHP 8.4 has been extended to four years. That means two years of security and bug fix updates and two further years of security updates only, so you can count on using PHP 8.4 until 2028 and plan for the long term.