Reader small image

You're reading from  Clean Code in PHP

Product typeBook
Published inOct 2022
PublisherPackt
ISBN-139781804613870
Edition1st Edition
Tools
Right arrow
Authors (2):
Carsten Windler
Carsten Windler
author image
Carsten Windler

Carsten Windler is a Lead PHP engineer at Plan A.
Read more about Carsten Windler

Alexandre Daubois
Alexandre Daubois
author image
Alexandre Daubois

Alexandre Daubois is a Symfony Developer at SensioLabs, the company that created Symfony.
Read more about Alexandre Daubois

View More author details
Right arrow

The version 8 revolution

As we have seen, PHP has experienced exceptional momentum in its evolution for the last few years. While we thought that version 7 was a real rebirth of the language, version 8 proved that it was only the beginning. Here are the main new features that will help you write clear and concise code, and that will help you to push even further the principles of clean code that we have seen throughout these chapters.

Match syntax

The match syntax is the condensed version of the classic switch/case. It should not be used everywhere because it can quickly become unreadable. However, if you choose the places where you use it sparingly, your code can become much clearer in an instant. Here is an example of the match syntax:

$foo = match($var) {
    ‹value 1› => Bar::myMethod1(),
    ‹value 2› => Bar::myMethod2(),
};

It works the same way as switch. However, note the difference in the...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Clean Code in PHP
Published in: Oct 2022Publisher: PacktISBN-13: 9781804613870

Authors (2)

author image
Carsten Windler

Carsten Windler is a Lead PHP engineer at Plan A.
Read more about Carsten Windler

author image
Alexandre Daubois

Alexandre Daubois is a Symfony Developer at SensioLabs, the company that created Symfony.
Read more about Alexandre Daubois