PHP. OOP. Classes inheritance

Главная » Tutorials » PHP » PHP. OOP. Classes inheritance

In this lesson we’ll continue to learn OOP in PHP. I recommend you to watch last lesson for your understanding of toda topic. Today we’ll discuss classes inheritance. Inheritance in php oop is one of the basic and key concept. Two others are encapsulation and polymorphism. We also will learn it today.

Let’s begin from theory – tha basics concepts of oop in php are encapsulation, inheritance and polymorphism.

Encapsulation is capability object or class to hide its internal implementation. They only give user public methods – interface of class. For example in real life you don’t ask yourself how computer saves your data. Because you have got “ready to use” tools – keyboard, mouse and other, which are interface between you and computer. In oop this interface is classes methods.

Inheritance, I am sure, is clear from the title. Class can inherit properties and methods from another class. For example, we inherited a lot from our parents.

Polymorphism is connected wth inheritance. It is object capability to redefine methods of parent classes. For example, in code below we redefined setName() method.

I would like to notice several important things:
try to follow the rule “one class in one file”, don’t define several classes in one file.
In child class you can call parent constructor, using parent:: keyword.

Last, I recommned you to read <a href=”http://php.net/manual/en/language.oop5.php” target=”_blank”>oop php chapter.</a>. I think, this chapter is described with difficult style, you need write some other articles with php  oop topic.

Подписаться на рассылку

Будьте в курсе - получайте последние статьи на свой email

Ваша подписка успешно оформлена

Pin It on Pinterest

Share This