‫So now we're going to look at inheritance where we can have subclasses.
‫So we have this user class.
‫And I just got rid of the getters and setters.
‫I got rid of all the instantiation and everything.
‫We just have three properties public name, public email, a protected status, a constructor that takes
‫in a name and email and a login.
‫So let's say that we have an ad.
‫We want to have an admin class that extends this user class.
‫So I'm going to come below the user class and create a new class called admin.
‫And the way that we can inherit from the user class is by using the extends keyword.
‫So we say class admin extends user okay.
‫And then let's say that we want to have a specific property for admins which is going to be level.
‫So we'll say public level.
‫And when I say level we'll just be like you know one through five just different different permissions
‫or whatever.
‫So so let's say in here we want to we want to be able to pass in the level when we instantiate a new
‫admin.
‫And since we're inheriting from the user class, we also want to pass in the name and email.
‫So let's create a constructor.
‫We'll say public function double underscore construct.
‫And in here we're going to take in name.
‫Email and level.
‫Okay.
‫Then what we're going to do is set the level right.
‫So this level that gets passed in just like we've set the name and email up here.
‫We're going to do that.
‫So this level.
‫Equals the level that's passed in.
‫Now, we don't do this for the name and email because we already have that in the parent constructor.
‫So we can actually get whatever is in the parent constructor by using this right here.
‫So we'll say parent and then double colon double underscore construct.
‫And then we can pass in the name and email.
‫So all this is doing.
‫Um, all this is doing right here.
‫Parent construct is calling this constructor method.
‫And what we're doing is passing in the name and email that's getting passed into the admin constructor.
‫So now what we can do is come down here and we can say admin, we'll call this admin one and we'll set
‫that.
‫We're going to instantiate a new admin.
‫All right.
‫And then let's pass in a name.
‫I'll say Tom Smith and an email Tom, at gmail.
‫And then for the level let's say five.
‫Okay.
‫And then I can do a print or let's do a var dump.
‫Of admin one.
‫And if I reload, you can see we have the name Tom Smith email and we have the, the, the level of
‫five.
‫And the stat we also have the status.
‫I should say that as well.
‫We didn't set that right because that has a default value up here as active.
‫And it says right here that status is protected.
‫Now since it's protected that means that we can access that.
‫In fact, before we do that, let me just show you that we can.
‫You know, if we wanted to access the the name and email, we can do that.
‫We can say admin one.
‫Name.
‫Echo Admin one.
‫Email.
‫Get rid of that.
‫Okay, so we got Tom Smith Tom at gmail so we can access that even though those properties were defined
‫up here, but where we're inheriting from this.
‫So we have access to those.
‫We also have access to login.
‫So if I say echo actually do we have to echo or do we do it up here.
‫No we did it in the function.
‫So I can just simply say.
‫Admin one.
‫Log in.
‫And we get Tom Smith logged in so I can do anything that the user can do.
‫Plus I have this this level that I can access.
‫So if I do admin one.
‫Level should see five, which is right here.
‫All right.
‫And let's say that we want to have a getter here that will get the status.
‫And we can do that because the status is protected, which means we can access it in subclasses.
‫So let's come down here and let's say public function get status.
‫And we're going to let's just echo out this.
‫Status.
‫And then I'll just get rid of all this and let's call admin one and.
‫Get status.
‫It's reload and we get active.
‫Now, again, if this status was private.
‫And I do that even though admin is a subclass, I still can't access status because it's it's private.
‫If I want to be able to get it in in an inherited class, then it needs to be protected.
‫So that will work.
‫So that's the basics of.
‫Of inheritance.
‫Now you can also override methods.
‫So let's say for instance the login it just says the name and then logged in.
‫Well what if we want the admin login to say admin and then the name logged in.
‫So we can just overwrite that by creating another login down here.
‫Let's say public function login.
‫And what I'll do.
‫Is this what we did here?
‫Except I'm going to echo.
‫Admin.
‫Before.
‫Before that.
‫So now if I call comment that out and let's say admin one.
‫Log in.
‫And reload.
‫We get admin Tom Smith logged in.
‫So this is an example of polymorphism where we have the same methods right.
‫We have a login for just a regular user.
‫And we have a login for the admin user.
‫But they do different things.
‫Okay, so that's pretty much all I wanted to do as far as inheritance at the moment.
‫So in the next video I want to talk about static members and static methods.