Implementing an Interface

Inheriting from an existing class is a very powerful tool in the OO programmer's arsenal. However, it's not always the appropriate one to use, because PHP doesn't allow a class to have more than one parent class.

This generally seems to be a good thing; it avoids the complexity that can be introduced with multiple inheritance. However, suppose that you had created a more abstract database result set class and derived your MySQLResultSet from it. With single inheritance it would be impossible for your class to also inherit from any other class.

For this reason PHP allows multiple inheritance, but only for interfaces. As you saw in Chapter 2, an interface is a class with no data members that declares but does not define ...

Get Object-Oriented PHP 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.