Which is better PHP or WordPress

PHP 8 - More performance for your WordPress

2. Some innovations from PHP 8 in detail

Going into detail about all the innovations of the new major release PHP 8 would go beyond the scope of this blog post. Therefore, we are only introducing some of the most important innovations in more detail. As a developer, however, it makes perfect sense to take a closer look at the new features in PHP 8, for example via the PHP project pages. Especially since programmers have to be prepared for some adjustments to their code. Let's start with the new Jit compiler. It promises performance improvements from which your WordPress website will also benefit.

 

New Jit compiler - the performance trump card

Certainly one of the most significant changes in PHP 8 is the new JIT compiler. JIT stands for "Just in Time". The JIT compiler ensures significantly more speed when generating dynamic websites on the web server. In order to understand the functional principle of the JIT compiler, first some background information on how PHP works:

PHP is a so-called interpreted language. Compared to languages ​​like C or Java, not the complete code is compiled, but the code is interpreted line by line for execution. This means that the PHP lines to be executed are always recompiled into machine code for the processor of the web server, line by line. This procedure is very resource-intensive, since the same lines of code have to be interpreted again and again. Computing time and memory are wasted. The JIT compiler promises a remedy by, in simple terms, compiling the components of the PHP code during runtime and making the repeatedly occurring code elements available to the processor of the web server in the cache, already interpreted.

 

 

The lines do not have to be reinterpreted over and over again, but can be executed directly as optimized machine code. JIT uses DynASM, a kind of dynamic assembler, to generate the native code from the PHP bytecode. The JIT compiler thus achieves significant performance improvements and reduces memory consumption. First performance tests with beta versions of PHP 8.0 showed a clear performance potential with this test code. The many small changes without a JIT compiler already managed to reduce the processing time by approx. 5%. With the JIT compiler, the processing time could then be halved, here PHP 8 was more than twice as fast as PHP 7.4. In everyday use this effect will definitely be less pronounced, but PHP remains a performance driver.

 

Union types

The union types newly introduced in PHP 8 may already be familiar to many from other programming languages ​​such as C. Union types allow several types to be combined into a union. All types combined in a union can be used and accept values ​​of different kinds. Before the introduction of union types with PHP 8, so-called phpdoc annotations had to be used in a rather complex manner. The advantage of the union types is a lower susceptibility to errors and faster detection of errors as well as a clearer syntax.

 

Named Arguments

Another new feature of PHP 8 are the named arguments, sometimes also referred to as named parameters. It is about the possibility of transferring input data to functions based on the parameter data. In addition, so-called array spreading is supported. Thanks to the named arguments, the code can be made cleaner and more flexible.

 

Weak maps

Weak maps are to be understood as a kind of continuation of the weak refs introduced in PHP 7.4. The term weak maps is a functionality that allows the garbage collector to delete objects if they are only referenced by the cache. This makes the handling of these objects much more resource-efficient and memory leaks in long-running processes can be avoided.

 

Attributes

Attributes are perhaps known to some from other programming languages ​​under the term annotations. It is structured metadata that can be used to describe the properties of objects, files and other elements. In PHP 7.4 you had to use so-called doc comments for this. Now you can use the attributes to add structured metadata with defined syntax to the declarations of functions, classes, parameters and other things. One or more attributes can be inserted in each declaration. Each attribute can have one or more values.

 



 

3. Other features of PHP 8 briefly listed

As already mentioned, there are many new features in PHP 8 and we have already discussed the most important of them. The following is a brief overview of some other changes, improvements and new functionalities in list form:

  • several new PHP functions such as str_contains, str_starts_with () and str_ends_with () or get_debug_type
  • Variable syntax tweaks
  • Static Return Type
  • Mixed type
  • Conversion of DateTime and DateTimeImmutable objects
  • fdiv function that allows dividing by 0 and supplies INF, -INF or NAN as return values
  • Applying :: class to objects
  • Stringable interfaces
  • Specification of numerous error messages
  • smarter reactions when working with multiple operators
  • Introduction of the decimal point in parameter lists
  • and a lot more

If you want to deal with PHP 8 in detail, you will find all the information you need on the PHP project pages including clear code examples.
The colleagues from t3n have also summarized PHP 8 very well.

 

4. How does the update work on PHP 8.0?

Immediately after the final release of PHP 8.0, we test the final version briefly and then roll it out across the server. After that, you can simply select it in the control panel. How it works and How to proceed if you are currently with another hosting provider, you can read again here under the tips for the PHP update. Our help article PHP Settings in Plesk is also recommended for Plesk users and HostPress customers.

 

 

 

Your hosting provider should ideally always provide the latest version of PHP. If you are looking for a reliable hosting partner who can help you quickly and easily with such matters, you should look out for a well-rated provider of managed WordPress hosting.
If you have any questions or comments about the PHP release, we look forward to your comment!