What’s New in PHP 8 (Features, Improvements, and the JIT Compiler)

06-10-2023 12:06 PM

PHP 8 has been officially released to the General Availability on November 26, 2020!

This new major update brings many optimizations and powerful features to the language. We’re excited to drive you through the most interesting changes that will allow us to write better code and build more robust applications.The most acclaimed feature coming with PHP 8 is the Just-in-time (JIT) compiler. What is JIT all about? “PHP JIT is implemented as an almost independent part of OPcache. It may be enabled/disabled at PHP compile time and at run-time. When enabled, native code of PHP files is stored in an additional region of the OPcache shared memory and op_array→opcodes[].handler(s) keep pointers to the entry points of JIT-ed code.”
So, how did we get to JIT, and what is the difference between JIT vs OPcache? To better understand what JIT is for PHP, let’s take a quick look at how PHP executes the source code to the final result.
Lexing/Tokenizing: First, the interpreter reads the PHP code and builds a set of tokens.
Parsing: The interpreter checks if the script matches the syntax rules and uses tokens to build an Abstract Syntax Tree (AST), a hierarchical representation of the structure of source code.
Compilation: The interpreter traverses the tree and translates AST nodes into low-level Zend opcodes, which are numeric identifiers determining the type of instruction performed by the Zend VM.
Interpretation: Opcodes are interpreted and run on the Zend VM.