PHP 8 was released on November 26, 2020. PHP 8 is a major version and has breaking changes from previous versions. New features and notable changes include:
Just-in-time compilation is supported in PHP 8.
PHP 8’s JIT compiler can provide substantial performance improvements for some use cases. PHP developer Nikita Popov has stated that the performance improvements for most websites will be less substantial than the upgrade from PHP 5 to PHP 7. Performance improvements due to the addition of the JIT compiler are expected to have more substantial performance improvements in mathematical-type operations than for common web-development use cases. Additionally, the JIT compiler provides future potential to move some code from C to PHP, due to the performance improvements for some use cases.
PHP 8 introduced the
match expression. The match expression is conceptually similar to a
switch statement and is more compact for some use cases. Because
match is an expression, its result can be caught into a variable or returned from a function.
PHP 8 introduced union types, a new
static return type, and a new
“Attributes,” often referred to as “annotations” in other programming languages, were added in PHP 8, which allow metadata to be added to classes.
throw was changed from being a statement to being an expression. This allows exceptions to be thrown in places that were not previously possible.