Hello, in this video we are going to take a look at class inheritance. So now we've got this one class, which is called vehicle. And I discussed that we could have, you know, this vehicle class which has basic property like speed acceleration wheels, and then we could have something a bit more specific like a car and a bike. So let's create a car class. And we would, you know, do the normal thing class call curly brace. And then in here, we can have constructors destructors.
We can have, you know, the variables, functions, all that stuff, but we've already got this vehicle class. And at the end of the day, this sort of functionality is common in a car we could have a function. So let's say five functions in here. That is called no means forward. So let's say when they use the presses the okay then this woman forward in this case, say for birds and birds right as well. So, instead of implementing all if functionality again, what we can do is put x here and then put the other plus.
So what this is saying is call extend vehicle, also known as inheriting vehicle vehicle will be the parent class and called will be the child class. So look at what happens if I get rid of this, and I just say call OBJ equals new car. And remember, even if we don't have a specific constructor in the back end, they will be constructed so you can either put these brackets or not I prefer to put the brackets because some languages force you to do this I think it's a good standard and whatever happened before this all OBJ and print all info and I call OBJ and move forward. So as you can see, it got the IRB gun. It also printed out all of this and he said the move forward plus the destructor as well. So there you go, even though we implemented No, you know, variables, or functions or literally anything in our cart and got all of this functionality, if we want something more specific to the call, maybe only the call can, you know, open doors for example, so we could say we create a function called Open Door.
And I say, Echo, again for brake line tag for some for my 10 if I also create a Vehicle object equals new vehicle. And if done via the dollar vehicle, as you can see, the function open door isn't there because vehicle doesn't have that functionality. Whereas car has all the functionality of vehicle and has some unique functionality. So I'm going to get rid of that because I don't want any of you know, all that, you know, printing to come out from the constructor and the destructor. But if I was to now go here, and say car OBJ open door. There you go.
It has its own unique functionality. Watch what happens if I create the constructor here. So if I actually create this construct so far, so function is going to school And now what we are going to say is echo. This is the call starting. And there you go. As you can see, if the actor child class has its own specific constructor, the same case is the destructor.
I went to, you know, test our app. But you know, he, as you can see, he will be the case. But as you know, x test just implemented destructor. If it has its own constructor, then then it will not run the parent constructor. You may want to run the parent constructor as well. And that's what I want you to do as an extra task.
I want you to figure out how to run the parent constructor for a child class. And really that's it for inheritance. You can have a novel Class is a code bike that inherits from vehicle, you could even have in some other maybe a truck, which also inherits from vehicle as well, you we can also have sort of multi tier inheritance. Or we can have, let's say, another class that inherits from this. So you'll get all of the properties of car, and you'll get all of the properties from the vehicle. So that is it.
What I would recommend, I recommend watching all of the videos in the object oriented programming series and in the PHP series in general, but especially with this video, check out the public versus private versus protected video in this little section because it's going to be really, really useful because you might have some potential problems later on. If you don't watch that video is to do with, you know, this public key word where I you know, cover all the nuances of this. So that's it. If you have any questions, feel free to pop me a message. And as usual, I look forward to seeing you in the next video.