WEBVTT

00:00.500 --> 00:03.890
I will call you back again to another video lecture in PHP.

00:03.890 --> 00:09.860
And in this video lecture we go ahead and look at inheritance in PHP.

00:16.940 --> 00:17.420
All right.

00:17.420 --> 00:24.560
So inheritance is uh, normal, like when we had the property of your parents or someone inherits your

00:24.560 --> 00:25.340
own property.

00:25.340 --> 00:29.750
So inheritance we have a class and also have a child class.

00:29.750 --> 00:34.400
So the parent class is a class that we inherit the property from.

00:34.400 --> 00:38.750
When a child class is one that inherits the property of the parent class.

00:38.870 --> 00:42.740
Now let's go ahead and say we have a class called Science Teacher.

00:42.740 --> 00:50.390
And this class we have the functions and we have function assays, teach physics, teach chemistry and

00:50.390 --> 00:51.410
teach biology.

00:51.410 --> 00:53.540
And another function teach chemistry.

00:53.570 --> 00:58.460
This teacher teaches the chemistry and another function teach physics.

00:58.460 --> 01:02.660
This teacher teaches physics and then another function teach biology.

01:02.660 --> 01:04.670
This teacher teaches biology.

01:04.700 --> 01:06.940
Now this is the function of this tissue.

01:06.970 --> 01:10.870
The function is how is physics chemistry and biology.

01:10.870 --> 01:12.520
And that is the science teacher.

01:12.550 --> 01:14.470
Now we have a child class.

01:14.500 --> 01:17.140
Let's go ahead and create a child class but without name.

01:17.140 --> 01:19.660
If we go ahead and uh print that out.

01:19.660 --> 01:24.880
So we have this declared right in here and uh, we are going to print that out.

01:24.910 --> 01:26.830
Go ahead and refresh and let's check it out.

01:26.830 --> 01:29.800
So we try to print out Teach chemistry.

01:29.800 --> 01:31.510
And this teacher teaches chemistry.

01:31.540 --> 01:34.060
Now let's go ahead and create a child class.

01:34.060 --> 01:36.910
And I'm going to say class.

01:36.910 --> 01:40.930
And let me go ahead and call that to be general teacher.

01:40.930 --> 01:51.820
So this teacher we actually teach everything, but uh, it's not a teacher but um, adds and uh, it's

01:51.820 --> 01:56.530
going to teach but science and adds, that is what this teacher needs to do.

01:56.530 --> 02:02.200
So if this teacher is going to do whatever that's the science teacher does.

02:02.200 --> 02:05.590
So whatever the science teacher does, this teacher will actually do that.

02:05.590 --> 02:09.220
So let's go ahead and see this general teacher we have right in here.

02:09.250 --> 02:12.290
We are now going to specify anything right in here.

02:12.320 --> 02:20.780
Now, what I'm going to do is I'm going to say this class teacher will now extend.

02:20.780 --> 02:29.030
So it extends to the science teacher which is the parent class.

02:29.030 --> 02:30.680
And now we have done that.

02:30.680 --> 02:33.110
We can now go down here.

02:33.140 --> 02:35.420
Let's go ahead and declare this.

02:35.420 --> 02:50.120
And I'm going to say this is a general teacher is equal to new general teacher.

02:50.120 --> 02:55.550
So when I create the object of this teacher right in here, so just created the object of this teacher

02:55.550 --> 02:58.190
and the the square head and print that out.

02:58.190 --> 03:00.890
So go ahead and say general.

03:03.200 --> 03:07.550
General teacher I mean greater than.

03:07.880 --> 03:12.500
And let me say it's going to teach um chemistry as well.

03:12.530 --> 03:15.530
So go ahead and say it teaches both chemistry.

03:15.550 --> 03:16.960
And let's go ahead and say that.

03:16.960 --> 03:19.660
So these teach chemistry.

03:19.690 --> 03:23.650
We supposed to also put this as a function because this is a function.

03:23.680 --> 03:26.950
Go ahead and put this function right in here and put a semicolon.

03:26.950 --> 03:28.150
So that is an error.

03:28.150 --> 03:29.500
But it actually is located.

03:29.500 --> 03:34.510
So go ahead and copy whatever you have right in here and then paste that here.

03:34.720 --> 03:36.880
So this and let's check it out.

03:36.880 --> 03:41.260
So this teacher teaches chemistry and this teacher teaches chemistry.

03:41.260 --> 03:45.760
And you can see I just created this class called General Teacher.

03:45.760 --> 03:49.540
And it extends to the current class science teacher.

03:49.540 --> 03:52.780
And we did not display anything right inside there.

03:52.810 --> 03:54.580
We didn't declare anything.

03:54.580 --> 03:57.340
We only use that keyword extends.

03:57.340 --> 04:04.990
And that's inherits the property of this, uh, science teacher, which is the parent class.

04:05.200 --> 04:08.080
So you can see that this really works fine.

04:08.740 --> 04:14.560
So we can actually go ahead and give this a class teacher, the general teacher, a function where we

04:14.560 --> 04:17.530
see we go ahead and create a function.

04:18.370 --> 04:26.510
And let's say that this teacher helm teach history because he is a general teacher.

04:26.510 --> 04:32.540
It can actually do everything the science teacher does and actually also do any other one it wants.

04:32.540 --> 04:34.580
So let's say it teaches history.

04:34.700 --> 04:38.600
And uh, inside here we'll go ahead and say it.

04:38.660 --> 04:48.680
So this teacher teaches history.

04:48.800 --> 04:52.610
So this teacher teaches history as well because he's a general teacher.

04:52.610 --> 04:54.620
And go ahead and apply semicolon at the end.

04:54.620 --> 04:59.510
And uh, let's go right in here and uh, paste this out.

04:59.540 --> 05:09.500
Let's go ahead and say go ahead and copy this teaches history and change it out to, uh, the chemistry.

05:09.530 --> 05:12.140
Let's go ahead and save this and refresh this.

05:12.170 --> 05:14.540
This teacher teaches history.

05:15.650 --> 05:20.840
So you can see that this teacher actually does whatever the current teacher does.

05:20.870 --> 05:25.930
And the current class, I mean, this child teach class.

05:25.930 --> 05:32.260
The child class, which is the general teacher, does everything that the parent class, which is the

05:32.260 --> 05:35.410
science teacher does, and it can actually do more.

05:35.830 --> 05:37.300
That is very interesting.

05:37.300 --> 05:42.970
Path of inheritance is a very interesting part of inheritance and is really very, very good.

05:42.970 --> 05:47.410
Now I'm going to another thing I will also show you, which is called overriding.

05:47.410 --> 05:51.460
So it can actually override the parent teacher.

05:51.640 --> 05:57.790
Let's say we have a teacher's biology inside here.

05:58.000 --> 06:00.430
Then we go ahead and say this is teachers biology.

06:02.950 --> 06:06.040
So if I go ahead and copy everything right in here.

06:08.620 --> 06:10.360
I will go ahead and press down right here.

06:10.600 --> 06:15.070
And uh, this is teachers biology.

06:18.580 --> 06:25.600
Now I will go ahead and say this teacher, instead of teaching biology, I will say this teacher.

06:25.630 --> 06:27.220
Teacher is a government.

06:37.170 --> 06:39.810
Okay, so this is our government.

06:40.410 --> 06:41.250
All right.

06:43.650 --> 06:48.420
And now if we go right in here and print out, let's copy this.

06:48.450 --> 06:54.840
The class, the function, uh, teaches biology.

06:54.840 --> 06:56.790
And we go over here and put choose biology.

06:56.820 --> 06:59.070
And let's save this and refresh.

06:59.460 --> 07:04.620
You can now see that the first one says teaches biology.

07:04.650 --> 07:06.720
This teacher teaches biology.

07:06.720 --> 07:11.130
And the second one says this teacher teaches government.

07:11.160 --> 07:11.760
It's over.

07:11.760 --> 07:12.240
Right.

07:12.270 --> 07:15.930
What it has in the first one, it's no longer printed out.

07:15.960 --> 07:17.280
What it has.

07:18.120 --> 07:20.130
Okay, what if you go and comment?

07:20.130 --> 07:26.790
If you comment this and say teaches biology is going to print out teaches, but let's go ahead and do

07:26.790 --> 07:26.940
that.

07:26.940 --> 07:29.250
So you see that I'll go ahead and cut off this.

07:29.250 --> 07:31.080
I've cut it off and I'm going to save it.

07:31.080 --> 07:32.670
And now let's go ahead and refresh.

07:32.670 --> 07:38.350
And you can see teacher teaches biology, and that is what is supposed to print what.

07:38.350 --> 07:42.400
We override that and then went ahead and print our own.

07:42.400 --> 07:43.810
So I have put it back again.

07:43.810 --> 07:50.140
And if I refresh, I see this teacher teaches biology and that is called override.

07:50.980 --> 07:59.800
So if the child class, which inherited the properties of the parent class, can actually override that

07:59.800 --> 08:06.700
property, some of the properties it gets from the Paris and do more and even do more with what it has.

08:07.120 --> 08:13.870
So that is very, very interesting aspect of uh, inheritance in PHP.

08:13.900 --> 08:16.600
So go ahead and put it down.

08:16.630 --> 08:21.850
Try as much as possible to play around with it because inheritance is being tossed with practical example.

08:21.850 --> 08:24.070
And that is why we take this step by step.

08:24.070 --> 08:29.950
So I believe at the end you go ahead and understand what inheritance is all about.

08:29.950 --> 08:32.740
So try this and I have a question.

08:32.740 --> 08:36.760
Use the question and answer section and I'm going to get back to you as soon as possible.

08:36.790 --> 08:37.690
Thank you so much.

08:37.690 --> 08:40.630
And I'm going to see you in the next video lecture.
