Book Image

The Art of Modern PHP 8

By : Joseph Edmonds
5 (1)
Book Image

The Art of Modern PHP 8

5 (1)
By: Joseph Edmonds

Overview of this book

PHP has come a long way since its introduction. While the language has evolved with PHP 8, there are still a lot of websites running on a version of PHP that is no longer supported. If you are a PHP developer working with legacy PHP systems and want to discover the tenants of modern PHP, this is the book for you. The Art of Modern PHP 8 walks you through the latest PHP features and language concepts. The book helps you upgrade your knowledge of PHP programming and practices. Starting with object-oriented programming (OOP) in PHP and related language features, you'll work through modern programming techniques such as inheritance, understand how it contrasts with composition, and finally look at more advanced language features. You'll learn about the MVC pattern by developing your own MVC system and advance to understanding what a DI container does by building a toy DI container. The book gives you an overview of Composer and how to use it to create reusable PHP packages. You’ll also find techniques for deploying these packages to package libraries for other developers to explore. By the end of this PHP book, you'll have equipped yourself with modern server-side programming techniques using the latest versions of PHP.
Table of Contents (19 chapters)
Section 1 – PHP 8 OOP
Free Chapter
Chapter 1: Object-Oriented PHP
Section 2 – PHP Types
Chapter 5: Object Types, Interfaces, and Unions
Section 3 – Clean PHP 8 Patterns and Style
Section 4 – PHP 8 Composer Package Management (and PHP 8.1)
Section 5 – Bonus Section - PHP 8.1

What this book covers

Chapter 1, Object-Oriented PHP, includes a quick overview of what OOP means and how it contrasts with functional and procedural styles. We review some popular OOP PHP projects that you might want to have a look at and then we go over the basics of classes, objects, interfaces, and namespaces.

Chapter 2, Inheritance and Composition, Encapsulation and Visibility, Interfaces and Concretions, following the theme of looking at OOP, explores inheritance in some detail and then contrasts this with a more modern approach of using composition. You are encouraged to download the code in order to get the most out of this chapter.

Chapter 3, Advanced OOP Features, the third and final chapter in Section 1, continues looking at OOP, and this time we're looking at the SPL (Standard PHP Library), exceptions and error handling, and finally meta-programming with reflection and attributes.

Chapter 4, Scalar, Arrays, and Special Types, explains that since PHP 7, types have become a major feature in modern PHP. This chapter looks at the simpler types, including scalars, arrays, and iterables, and then the "nothing" types of null, void, and uninitialized.

Chapter 5, Object Types, Interfaces, and Unions, continues looking at types, but our focus shifts onto looking at exactly how the type system works when dealing with classes and interfaces.

Chapter 6, Parameter, Property, and Return Types, the final chapter in Section 2, looks at how types can be enforced strictly and examines their usage as parameter, property, and return types. We conclude by looking at covariance and contravariance and confirm how this works in PHP 8.

Chapter 7, Design Patterns and Clean Code, moves on from learning about the language itself and starts to look at ways we write it. We look at some clean coding practices and then have an overview of design patterns that are tried and tested approaches to common requirements.

Chapter 8, Model, View, Controller (MVC) Example, sees us work through the MVC pattern by building a toy MVC system. You are definitely encouraged to download the code for this chapter.

Chapter 9, Dependency Injection Example, as in Chapter 8, Model, View, Controller (MVC) Example, looks to learn by doing, and this time our goal is to understand all about DI. We will create an entire toy DI container to understand how this pattern works.

Chapter 10, Composer for Dependencies, introduces Composer—one of the most important things to happen in the PHP world. We will learn how to use Composer to use third-party packages in our projects.

Chapter 11, Creating Your Own Composer Package, continues with Composer but this time looks at how we can use it to create our own packages, share them with our private projects, and even publish them for the benefit of the PHP community.

Chapter 12, The Awesomeness That Is 8.1, the final chapter of the book, is all about PHP 8.1 and the excellent new features that are included in this new release. It is not an exhaustive list but instead focuses on a selection of features that are most likely to matter to you day to day.