This article writes about what is new in PHP 8.0. These are personal notes related to Symfony UX, taken while attending the “Keynote: What’s new in PHP 8.0?” lecture by Nikita Popov at SymfonyWorld Online 2020.
Table of Contents
PHP is constantly improving, adding optimizations and new features. Developers working in the PHP world should welcome these changes with curiosity because it will, at some point, impact their way of working.
At the time when I am writing this article, there is the latest PHP 8.0 release with many new features and optimizations. Nikita Popov made a fantastic overview of the most important ones.
Just in Time (JIT) Compiler
Just in Time (JIT) Compiler compiles PHP code to x86 machine code to improve performance, at least in theory.
To use it we just need to enable opcache and set opcache to antyhing that is not 0 MB, for example
Nikita presented some nice benchmarks on how JIT compiler behaves against various php examples.
Attributes are normal classes that have attribute attribute 🙂 Attributes bythemselves don’t do anything. In order for them to do anything
Named Arguments in PHP 8
Some syntax sugar improvements come with constructor promotion. PHP automatically creates corresponding properties and assigns corresponding values.
int|false or int|string|null
It looks like mixed type is the same as no type at all. However, this is not completely true.
mixed for parameters, and mixed for return type, there is a difference.
Static Return Type
Replacement or improvement for switch statements.
Match is an expression with return value.
Match performs comparison with strict type comparison === instead of ==.
The latest version of PHP brings lots of new features, with the biggest highlights to the JIT compiler and continued efforts on improving the strongly typed paradigm.
Most of the deprecated functionalities from previous versions are removed in PHP 8.
There is a long term goal to convert all resources to objects in PHP. The reason for this is that objects are type-safe and have much better internal support.
PHP keeps growing and delivering more powerful features. Community is strong and development tools are getting better and better.
It is definitely worth learning about PHP development, either by reading a good book about PHP 8 or surfing online and checking our various tutorials and official documentation.
Read more about SymfonyConference Online 2020 and discover my other notes.