Object-Oriented PHP Part 3

In this series, we’ll continue to build the spaceship app that we’ve started in Introduction to Object-Oriented PHP and Object-Oriented PHP Part 2. In this series we will explore the inheritance in PHP through abstract classes and methods. We'll also take a look at how to create and implement interfaces.

Tutorials in this course
More information

In this series, we’ll continue to build the spaceship app that we’ve started in Introduction to Object-Oriented PHP and Object-Oriented PHP Part 2. In this tutorial, I’ll show you how to use the extends keyword in PHP so that you can use it to inherit properties and methods from another class.

Additional resources

Object Inheritance (PHP Manual)

More information

In this tutorial, I will show you how to override a method that you’ve inherited from another class. By having two classes we are starting to shape the different behaviors and properties of each, while still keeping most things in common and not duplicated.

More information

In this tutorial, I will show you the difference between public, private, and protected methods or properties in PHP classes. By the end of this lesson you will learn how to make things private at first, protected once you need to access them in a subclass, and public when you need to use it outside of its class and subclass.

Additional resources

Visibility (PHP Manual)

More information

In this tutorial, I will show you how to get around the problem of calling a function that you have overridden in your class: how to call the parent class method.

Additional resources

Scope Resolution Operator (::) — PHP Manual

More information

In this tutorial, I will show you how we can build a better blueprint and hierarchical structure for our app’s classes through the use of abstract classes.

Additional resources

Class Abstraction (PHP Manual)

More information

In this tutorial, I will show you the power of abstract classes and how you can enforce subclasses to define certain functions. In this way, you can share logic but for things that are really specific to subclasses, you can force them to define certain functions, but with the specific logic required.

Additional resources

Class Abstraction (PHP Manual)

More information

In this tutorial, I will show you how to extend an abstract class and ensure that all the methods that are required by the abstract class are included in this new class.

Additional resources

Class Abstraction (PHP Manual)

More information

In this tutorial, I will show you how to handle new requirements for data storage by creating two smaller abstract classes out of our original data storage class. By creating these new abstract classes, we can build more flexibility into our code.

Additional resources

Class Abstraction (PHP Manual)

More information

Now that we have created new abstract classes, we need to load and utilize them in our code. In this tutorial, I will show you how we can refactor our code to make use of our new abstract data loading classes.

More information

We have an abstract class with methods that we require, but there’s no logic in these abstract methods. This is a perfect opportunity to use interfaces. In this tutorial, I will show you how to create and implement Interfaces. I will also explain how interfaces are useful when you will be sharing your code. But even if you’re not creating interfaces to share, chances are, if you’re using open source code — and definitely in Drupal — you will need to know how to implement interfaces.

Additional resources

Object Interfaces (PHP Manual)

This course appears in the following guides:
Categories
Module Development, Backend and Infrastructure
Drupal 7, 8, 9, and 10