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...