Did you know that the official release date of the new PHP 8 is December 3rd, 2020?
The new version of the PHP 8 will include a lot of breakthrough changes, as well as further improvements in performance, and even newly added features! With all of the new changes that are coming to PHP 8, prepare yourself to make some changes in your code to get yourself back up and running.
Keep in mind that if you’ve kept your code up-to-date, you likely won’t have too hard of a time getting everything back up and running. Are you interested in learning what to expect from PHP 8?
We’ve created a complete guide for you here. Keep reading to learn about the breakthrough changes and new features in PHP 8!
What Are the New Features That Come With PHP 8?
Let’s first start off with the new features that you can find in PHP 8! Since PHP 8 is still currently in active development, you can expect this list to continue growing.
Just in time, also referred to as JIT, sees huge improvements in performance. While this doesn’t mean that it is improving within web requests, there are more thorough benchmarks.
New Types of Static Returns
Before PHP 8, static wasn’t a valid return available. However, as a result of the dynamically typed character of PHP 8, having a new static return type will prove to be very useful.
If you’re unsure what union types are, they’re a collection of two (or more) types and designate which type will be used. In the updated PHP 8, any nullable unions can be recorded as ? or as |null.
New Mixed Types
The mixed type is something that a lot of developers have mixed feelings about. However, there’s one thing that can be agreed upon — when there’s a missing type, it can wreak havoc. Some of the things that you can expect to see with a missing type in PHP include:
- Expecting one of several types
- A function is null or doesn’t return anything
- A type appears that can’t be type hinted
By adding a mixed type, you can expect to see one of the following types:
You should also be aware that since mixed already has null, PHP isn’t allowed to make the type nullable. In fact, it will simply trigger an error.
Breaking Down the PHP JIT
One of the newest updates to PHP 8 is JIT! JIT was executed to be independent of OPcache.
There may be times where JIT is disabled (or enabled) at run time and during the compile time. When JIT is enabled, files that contain native code will be stored in an extra section of the shared memory in OPcache.
What’s the Difference Between JIT and OPcache?
The entirety of the execution process of PHP includes:
- Tokenizing, which is where the coding interpreter will read through the PHP code and develop a selection of tokens.
- Parsing, which is when the interpreter will look through to ensure that the script matches the tokens that were used to create an AST, as well as to make sure that the syntax rules are matching.
- Compilation, which is when the AST is translated into low-level Zend opcodes. This creates identities that allow the interpreter to identify the Zend VM instruction.
- Interpretation, which allows the Opcodes to be interpreted to be able to run on Zend VM.
How does working with OPcache make PHP run faster? By using the OPcache extension, preloading, and JIT!
Since PHP is interpreted, it means that when PHP is running, the interpreter has to parse, comply, and finalize each request, every time a new one is made. This results in CPU resources being wasted.
By using the OPcache extension, it helps to improve the overall performance of the PHP by using precompiled script bytecode. This code is stored in the shared memory, which eliminates the need for PHP to parse, comply, and finalize each individual request that’s created.
This means that the PHP interpreter will only have to go through the four-step process that we discussed early the first time that the script is enabled. Since these bytecodes are immediately available in the stored memory, they can be easily accessed as low-level intermediate representation and used towards Zend VM.
The Just in Time compiler uses the immediate parts of code and uses them into machine code. This is beneficial, as it forces a bypass compilation. This improves both the memory usage and the performance of PHP.
However, like the previous attempts – it currently doesn’t seem to significantly improve real-life apps like WordPress. It’s planned to provide additional effort, improving JIT for real-life apps, using profiling and speculative optimizations.
Understanding What to Expect From PHP8
By reading through this guide, we hope that you have a better idea of what to expect from PHP 8 when it’s released! In this guide, we covered the majority of the improvements, new additions, and the most important changes that you can expect to see from PHP 8.
One of the most talked-about sections is the JIT compiler, but know that there’s so much more that will be added with PHP 8!
Are you interested in learning more about how PHP 8 can benefit you? Feel free to schedule a tour with us today to learn more about why we have the best WordPress Managed Hosting!
Zach has 12+ years of experience with WordPress, from creating and maintaining client sites, to providing support and developing documentation. A knack for problem-solving and providing solutions led Zach to pursue a job with Automattic providing customer support in 2015 working with WooCommerce support, and now Zach has recently joined our team here at Pressable. Outside of work, Zach enjoys spending time with his family, playing and watching sports, and working on projects around the house.