25. Conclusion
This document has presented the PHP 8 language through numerous scripts and a common theme—the calculation of income tax—developed in 13 versions:
- Versions 1 and 2 implement the calculation using functions and text files or JSON;
- Version 3 writes it using classes, and Version 4 organizes it into layers [dao] / [business] / [console], tested with [PHPUnit];
- versions 5 through 7 retrieve tax data from a database ([MySQL]), then [PostgreSQL], and then from one or the other based on a simple configuration file;
- versions 8 through 11 convert the calculation into a web service, with a console client: authentication, sessions, logging, sending emails to the administrator, cache [Redis], responses JSON and then XML;
- Version 12 is a web application (MVC) that can respond in JSON, XML, or HTML, with its console client;
- Version 13 protects the application files by making only the [public] folder visible from the web.
Along the way, we’ve covered most of what PHP 8 offers compared to PHP 7: strict typing and the types of parameters, results, and attributes; read-only classes and attributes, constructor parameter promotion, enumerations, property hooks, and the asymmetric visibility of PHP 8.4; the [match] expression, the null-safe operator, named arguments, and the pipe operator from PHP 8.5; errors that have become exceptions; the new API, [PDO], and [DOM]. We have also seen, each time, what PHP has dropped: none of the scripts in this document display a [Deprecated] message with PHP 8.5.
The server architecture of version 12 (a main controller, secondary controllers, the [business] and [dao] layers, responses JSON, XML or HTML) is that of modern web frameworks, such as [Symfony] or [Laravel], some of whose components we have, in fact, used ([HttpFoundation], [HttpClient], [Mailer]). Readers who have completed this course now have the foundation to tackle one of these frameworks.
The JSON web service in version 12 can also have clients other than the console client written in PHP: a JavaScript client running in a browser, a mobile app, etc. This is the client/server architecture presented in the introduction to this document.
Training courses for Serge Tahé are available at https://stahe.github.io.