What’s new in PHP 8.0, SymfonyWorld Online 2020

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

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 opcache.jit_buffer_size=128M

Nikita presented some nice benchmarks on how JIT compiler behaves against various php examples.

Attributes

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

Constructor Promotion

Some syntax sugar improvements come with constructor promotion. PHP automatically creates corresponding properties and assigns corresponding values.

Union Types

int|false or int|string|null

Mixed Type

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

Match Expressions

Replacement or improvement for switch statements.

Match is an expression with return value.

Match performs comparison with strict type comparison === instead of ==.

Nullsafe Operator

Summary

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.

milan.latinovic

Senior PHP Engineer and Enterprise Architect at apilayer GmbH. Topics of interest: Software development, PHP, Java, Python, REST API, OpenApi, MySQL, Microservices, Integrations, Interfaces, Interoperability, Processes, Solution Architecture, LDAP, Azure

Recent Posts

Code Review Best Practices: Code reviewing and being reviewed

This article is about the code review best practices. It explains code review from the… Read More

2 years ago

What are the best Practices in REST API design

API design is an important aspect of modern software development. It allows different systems to… Read More

2 years ago

Next Industrial revolution: What is ChatGPT? Will it replace jobs?

This article sheds some light related to the question will ChatGPT or AIs in general… Read More

2 years ago

What is new in PHP 8.2: What are new features, what is deprecated?

This article provides an overview of new features and deprecations in PHP 8.2. PHP 8.0… Read More

2 years ago

Automation and AI in Software Engineering

This article is about Automation and Artificial Intelligence in Software Engineering: Experiences, Challenges, and Opportunities.… Read More

4 years ago

Enumerations in PHP 8.1 – with code example and references

PHP is getting more and more features. Enumerations in PHP are one of the latest… Read More

4 years ago