PHP – Inheritance and Overload in a Class

Have you ever dreamt to understand the inheritance and the overload from once 5 minute example? No such dreams? Anyway, in case you ever tend to think about it, here is the example with PHP.

Let’s imagine that we have two classes – a normal person and an athlete. The normal person has name, age and city, and the athlete has all of those plus a bunch of sports he is good at. Thus, the athlete inherits the person 🙂

Furthermore, they both have a method called “get_information”. Thus, if you want to get the information for the person, you receive a small string about his name and city and for the athlete you receive name, city, age and sports in a nice green table.

Like in the example below:

phpInheritance

How was this achieved? With the beautiful code below:

Available also in GitHub.

Enjoy it!

Tagged with: , ,