Extending a Class Through Inheritance

One of the major advantages of OOP is that you don't always have to start from scratch. Existing classes may be able to do the job for you. If an existing class does exactly what's required, then you can simply use it "as is." If it does something similar, but not exactly what you need, you can adapt it. This process of adaptation is called inheritance.

Inheritance is one of the most important features of object-oriented (OO) languages. It allows us to create new classes from existing ones, exploiting behavior that is already defined and adjusting it as necessary. The term "inheritance" is appropriate because the data members and methods of the original class become part of the newly created class. However, ...

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.