Chapter 2: Inheritance and Composition, Encapsulation and Visibility, Interfaces and Concretions

In this second chapter, we are going to learn as much as we can about the OOP features of PHP when it comes to creating full sets of classes that are related to each other and that work together to provide a specific feature.

First, we are going to learn about encapsulation and the differences between private, protected, and public class properties and methods. Hopefully, you will see the advantage of keeping things as private as possible.

Then we are going to look in detail at the two main ways of creating a graph of related and interdependent classes: classic inheritance and the alternative approach of composition.

As we explore this, I hope that ...

Get The Art of Modern PHP 8 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.