WEBVTT

00:00.500 --> 00:00.830
I will.

00:00.830 --> 00:03.410
Going back again to another video lecture in PHP.

00:03.440 --> 00:08.720
And in this video lecture we go ahead and look at classes in PHP.

00:15.530 --> 00:19.790
So PHP is an object oriented programming language.

00:19.820 --> 00:22.880
So we are going to learn about classes.

00:22.970 --> 00:26.900
So classes is just a blueprint.

00:26.930 --> 00:30.950
It can be called a specification for a custom data type.

00:30.950 --> 00:37.730
So what I mean is that in PHP you can able to create some data types like integer data types, strings

00:37.730 --> 00:40.580
data types and boring data types.

00:40.580 --> 00:45.770
Then these alphabets and these are numbers.

00:45.770 --> 00:48.830
And there are two of those for Boolean and so on.

00:48.830 --> 00:57.740
But there are some things we want to be able to represent like a objects something like your yourself

00:57.770 --> 01:04.960
car book, laptop and foams and you'll be like, how do we represent this?

01:04.960 --> 01:07.570
So that is where classes come in.

01:07.570 --> 01:12.550
It enables us to create our own custom data type.

01:12.610 --> 01:20.230
So once we are talking about classes, we are trying to create your own custom data types because we

01:20.230 --> 01:27.880
have that ability to create normal data types like integers, uh, strings, booleans and so on.

01:27.970 --> 01:34.990
So we can create our own custom data types because we can't represent everything in variables like string

01:34.990 --> 01:36.670
numbers or booleans.

01:37.090 --> 01:42.370
So and by creating our own custom data types we are creating uh classes.

01:42.370 --> 01:46.210
So class is a specification of a custom data type.

01:46.600 --> 01:51.250
And we can use that to model anything we want to do.

01:51.280 --> 01:58.720
Now let me go ahead and uh, let us do this with a practical example.

01:58.930 --> 02:10.270
Let me go ahead and say I want to create a class of a car, and then this class of a car is a blueprint

02:10.300 --> 02:16.840
about a car, and the editor module creates a class of anything.

02:16.870 --> 02:23.890
You are going to break that down into variables of, uh, let me say I'm going to break that down into

02:23.920 --> 02:24.910
attributes.

02:25.330 --> 02:31.090
Now, if I want to break down cars or the attributes of a car, like the year the car was made, the

02:31.090 --> 02:36.490
color of the car, the manufacturing and the name of the car.

02:36.490 --> 02:40.480
So we go ahead and, uh, create a curly brace.

02:40.480 --> 02:44.530
And here I'm going to break down the attributes of this car.

02:44.530 --> 02:48.580
So if I want to break that down I'll put them into variables.

02:48.580 --> 02:55.480
So I'm going to say var and then I'm going to actually put in.

02:55.510 --> 02:59.020
Let me say the first one is the name of the car.

02:59.470 --> 02:59.950
Right.

02:59.950 --> 03:02.850
So And, uh, let me see.

03:02.850 --> 03:06.930
The next one I want is the year of the car.

03:08.730 --> 03:13.470
Then the next one is the color of the car.

03:13.500 --> 03:17.610
Now, these are the blueprints or the attributes of this car.

03:17.610 --> 03:24.690
So the class is the blueprint and the whatever it is in there is the actual bus and the the actual bus

03:24.720 --> 03:26.070
is what we are going to use.

03:26.070 --> 03:28.200
We have not created the real object.

03:28.230 --> 03:30.000
Now we have gotten the actual bus.

03:30.030 --> 03:34.710
What we need to do now is to go ahead and create an object of this car.

03:34.710 --> 03:39.870
So the object of the car is known as the instance of the class.

03:41.220 --> 03:48.510
So the object we are creating is not at the instance of that class, the actual car which we are going

03:48.510 --> 03:51.300
to model and which the objects are going to create.

03:51.330 --> 03:53.490
Now let's go ahead and create that.

03:53.520 --> 03:58.410
I'll go ahead and say create this variable called car and let me call out to be car one, because we

03:58.410 --> 04:01.640
might be dealing with more or different cars and they're their guidance.

04:01.670 --> 04:02.030
See?

04:02.060 --> 04:03.950
New car.

04:03.980 --> 04:07.310
Now we have a new car, kind of with a semicolon.

04:07.340 --> 04:10.700
Now this, which we created right in here.

04:10.700 --> 04:17.480
The new car is the object of this car, which is the instance of the actual class.

04:18.440 --> 04:24.980
So now let's go ahead and specify the this attributes which we just created over here.

04:25.010 --> 04:30.290
So here is where I'm going to give in the name of the car the year and the color.

04:30.320 --> 04:36.800
So I'm going to say car one then.

04:36.830 --> 04:46.370
And for me to give the first one is the name I'm going to say car one name.

04:48.050 --> 04:52.850
Then the name of this car is going to say this is a Toyota.

04:54.800 --> 04:57.320
So you can model anything right in here.

04:57.350 --> 05:01.970
Then the next one is it's going to gonna see.

05:01.970 --> 05:05.870
The next one is to one.

05:07.880 --> 05:09.140
Is the year.

05:11.510 --> 05:15.170
And let this year be equal to.

05:15.500 --> 05:17.450
We have our 20.

05:19.460 --> 05:20.570
2030 model.

05:21.050 --> 05:21.410
Right.

05:21.410 --> 05:25.370
So depending on the time you're taking this it might have come out by then.

05:25.400 --> 05:32.420
Then the next one is a the next attribute we have like right in there is a color.

05:33.530 --> 05:37.100
Then let the color be equal to black.

05:37.100 --> 05:40.400
So let's use a color that is a universal.

05:40.430 --> 05:44.660
Now you can go ahead and print out these.

05:44.870 --> 05:51.980
We have created the object of this car which is this which we have right here, the new car okay.

05:52.010 --> 06:00.830
Now what we need to do now is we go ahead and print out these.

06:00.860 --> 06:03.340
For me to do that, to go ahead and say echo.

06:03.370 --> 06:04.810
And there are Korhonen.

06:04.840 --> 06:05.230
See?

06:08.380 --> 06:12.640
Go ahead and say car one.

06:13.570 --> 06:17.680
And then you print out any of the attributes which you want to print out.

06:17.680 --> 06:23.440
Maybe if it is, the name can go ahead and say the name and a semicolon at the end.

06:23.440 --> 06:26.140
And if I refresh this we have Toyota.

06:26.710 --> 06:33.550
You can see that now if you want to print out the year it's going to say the year.

06:33.640 --> 06:37.720
And then go ahead and save this and print this out 2030.

06:39.310 --> 06:43.630
If you are dealing with the color you can go ahead and say color.

06:43.720 --> 06:46.570
And then that is black.

06:46.600 --> 06:50.890
Now you can create so many of these objects of this car.

06:50.920 --> 06:53.410
Now you can go ahead and create a car too.

06:54.100 --> 07:00.850
Let's go ahead and see that car two is equal to new.

07:03.870 --> 07:04.800
New car.

07:05.220 --> 07:08.250
So K2 is equal to a new car with a semicolon at the end.

07:08.250 --> 07:16.560
And then we go ahead and copy everything we have here so we can just, uh, just say, uh, edit that.

07:16.590 --> 07:22.410
Now go ahead and change this to .2.2.

07:22.440 --> 07:23.100
All right.

07:24.810 --> 07:30.690
So change this as well to dot two and change this to cart two.

07:31.590 --> 07:35.820
So I mean the next car should be like uh named as Nissan.

07:36.660 --> 07:47.550
Then maybe this is a in the year 2070 and then color the equal to white.

07:50.760 --> 07:52.710
Now let's go ahead and save this.

07:53.130 --> 07:59.100
So for us to do that just go ahead and say equal to or sorry this is car two.

07:59.130 --> 08:02.760
And if we check the color check out and that is white.

08:03.120 --> 08:06.900
So in this way you can be able to create your own custom data type.

08:06.900 --> 08:13.410
And there you go ahead and model it by creating a class, creating an object which is the instance of

08:13.410 --> 08:14.190
the class.

08:14.190 --> 08:19.590
And then we can be able to break or use the attributes to do whatever you want.

08:19.620 --> 08:26.820
So I want to look more into the classes and the the object oriented programming as you move into this

08:27.180 --> 08:28.080
class.

08:28.290 --> 08:37.050
So for had I checked out this and know that the classes are custom data types which you create and the

08:37.050 --> 08:43.740
objects are instance of the class which you create, which is the abstract car which you are creating

08:43.740 --> 08:43.950
here.

08:43.950 --> 08:46.440
So you can model anything you want right in here.

08:46.440 --> 08:49.830
And then you go ahead and check it out.

08:49.830 --> 08:51.270
So play around with it.

08:51.270 --> 08:55.200
And if you have any questions under this use the question and answer section.

08:55.200 --> 08:58.110
And I'm going to get back to you as soon as possible.

08:58.140 --> 08:59.190
Thank you so much.

08:59.190 --> 09:02.700
And I'm going to see you in the next video lecture.
