I will call you back again to another video lecture in PHP.
And in this video lecture we go ahead and look at inheritance in PHP.
All right.
So inheritance is uh, normal, like when we had the property of your parents or someone inherits your
own property.
So inheritance we have a class and also have a child class.
So the parent class is a class that we inherit the property from.
When a child class is one that inherits the property of the parent class.
Now let's go ahead and say we have a class called Science Teacher.
And this class we have the functions and we have function assays, teach physics, teach chemistry and
teach biology.
And another function teach chemistry.
This teacher teaches the chemistry and another function teach physics.
This teacher teaches physics and then another function teach biology.
This teacher teaches biology.
Now this is the function of this tissue.
The function is how is physics chemistry and biology.
And that is the science teacher.
Now we have a child class.
Let's go ahead and create a child class but without name.
If we go ahead and uh print that out.
So we have this declared right in here and uh, we are going to print that out.
Go ahead and refresh and let's check it out.
So we try to print out Teach chemistry.
And this teacher teaches chemistry.
Now let's go ahead and create a child class.
And I'm going to say class.
And let me go ahead and call that to be general teacher.
So this teacher we actually teach everything, but uh, it's not a teacher but um, adds and uh, it's
going to teach but science and adds, that is what this teacher needs to do.
So if this teacher is going to do whatever that's the science teacher does.
So whatever the science teacher does, this teacher will actually do that.
So let's go ahead and see this general teacher we have right in here.
We are now going to specify anything right in here.
Now, what I'm going to do is I'm going to say this class teacher will now extend.
So it extends to the science teacher which is the parent class.
And now we have done that.
We can now go down here.
Let's go ahead and declare this.
And I'm going to say this is a general teacher is equal to new general teacher.
So when I create the object of this teacher right in here, so just created the object of this teacher
and the the square head and print that out.
So go ahead and say general.
General teacher I mean greater than.
And let me say it's going to teach um chemistry as well.
So go ahead and say it teaches both chemistry.
And let's go ahead and say that.
So these teach chemistry.
We supposed to also put this as a function because this is a function.
Go ahead and put this function right in here and put a semicolon.
So that is an error.
But it actually is located.
So go ahead and copy whatever you have right in here and then paste that here.
So this and let's check it out.
So this teacher teaches chemistry and this teacher teaches chemistry.
And you can see I just created this class called General Teacher.
And it extends to the current class science teacher.
And we did not display anything right inside there.
We didn't declare anything.
We only use that keyword extends.
And that's inherits the property of this, uh, science teacher, which is the parent class.
So you can see that this really works fine.
So we can actually go ahead and give this a class teacher, the general teacher, a function where we
see we go ahead and create a function.
And let's say that this teacher helm teach history because he is a general teacher.
It can actually do everything the science teacher does and actually also do any other one it wants.
So let's say it teaches history.
And uh, inside here we'll go ahead and say it.
So this teacher teaches history.
So this teacher teaches history as well because he's a general teacher.
And go ahead and apply semicolon at the end.
And uh, let's go right in here and uh, paste this out.
Let's go ahead and say go ahead and copy this teaches history and change it out to, uh, the chemistry.
Let's go ahead and save this and refresh this.
This teacher teaches history.
So you can see that this teacher actually does whatever the current teacher does.
And the current class, I mean, this child teach class.
The child class, which is the general teacher, does everything that the parent class, which is the
science teacher does, and it can actually do more.
That is very interesting.
Path of inheritance is a very interesting part of inheritance and is really very, very good.
Now I'm going to another thing I will also show you, which is called overriding.
So it can actually override the parent teacher.
Let's say we have a teacher's biology inside here.
Then we go ahead and say this is teachers biology.
So if I go ahead and copy everything right in here.
I will go ahead and press down right here.
And uh, this is teachers biology.
Now I will go ahead and say this teacher, instead of teaching biology, I will say this teacher.
Teacher is a government.
Okay, so this is our government.
All right.
And now if we go right in here and print out, let's copy this.
The class, the function, uh, teaches biology.
And we go over here and put choose biology.
And let's save this and refresh.
You can now see that the first one says teaches biology.
This teacher teaches biology.
And the second one says this teacher teaches government.
It's over.
Right.
What it has in the first one, it's no longer printed out.
What it has.
Okay, what if you go and comment?
If you comment this and say teaches biology is going to print out teaches, but let's go ahead and do
that.
So you see that I'll go ahead and cut off this.
I've cut it off and I'm going to save it.
And now let's go ahead and refresh.
And you can see teacher teaches biology, and that is what is supposed to print what.
We override that and then went ahead and print our own.
So I have put it back again.
And if I refresh, I see this teacher teaches biology and that is called override.
So if the child class, which inherited the properties of the parent class, can actually override that
property, some of the properties it gets from the Paris and do more and even do more with what it has.
So that is very, very interesting aspect of uh, inheritance in PHP.
So go ahead and put it down.
Try as much as possible to play around with it because inheritance is being tossed with practical example.
And that is why we take this step by step.
So I believe at the end you go ahead and understand what inheritance is all about.
So try this and I have a question.
Use the question and answer section and I'm going to get back to you as soon as possible.
Thank you so much.
And I'm going to see you in the next video lecture.