 Hello, this is Christian. Welcome to episode three of this video series. This time we'll focus on interfaces in PHP. So here again, the list of interfaces where you cannot do with it. Interfaces can extend many other interfaces only. It cannot have any abstract methods. It cannot have a constructor. As you can see, the list of cannot is actually more than the can list here. Okay, so let's take a look at how they're related in a class in interface in PHP. So in here, in the previous video, we did some examples using the Animal Kingdom as classes and abstract classes and concrete classes. Okay, so let's add another one here. Yeah, let's just start over here. Create another file we'll call this just interfaces. Okay, so interfaces are very, very broad. Think of it like the interfaces of a musical instrument of your car, right? Anything that you can plug into and then you don't really care what's inside, what's happening inside the black box. Those are the interfaces that you can use to connect it to. That's very broad. So interfaces are declared as follows. You can have the, you need to use the word interfaces or interfaces, I'm sorry. Follow by the name of that interface. So for example, if you talk about the Animal Kingdom, we can say a species could be an interface. Okay, so very broad. And then what does it do? Okay, so I'm, I should have picked a different type. I don't know much about species. But so here you cannot have variables. So you cannot have private data, things like that. Okay, you cannot, if you mouse over that, the ID will tell you that interfaces may not include member variables. Okay, so that's a no-no. What about functions? If you put functions maybe like age, can you do that? And since we yes and no, if you mouse over that red thing says excess type must be omitted. So that means you cannot have the word public or private here. It's always going to be public by default. You can make it public. I think that should be fine. But you cannot have it private because otherwise, you know, is this privacy where you can use it. So either public or just leave it out. If you leave it out, just the default. So there it is a function. I like to use the public in there just to be consistent with your code. So this is a function definition only. Okay. I cannot have a function. For example, I don't know. It doesn't make sense with the species here anyway. Maybe like get name with something, right? You cannot implement a function like this. It's a function implementation because we have the full color basis in here. So if you mouse over that, it will tell you cannot have body. Okay. So it's body less. So you just need to be like that. Okay. So this is very limited to what you can do with interfaces. And you cannot have a constructor either. If I go here, function constructor, right? You can have a, again, because after all, it's just a function. If you do it this way, but you cannot have a constructor like this. So it breaks the rule for that interface. So if it's like this, then yeah, that's fine. It would treat as a constructor, but it's not complete. So whatever it is, you need to implement that. Okay. So really, we don't really need this because there's no point. Okay. So that's all you can do with that. Now we'll talk about traits later in the next course. But it does have, you cannot use traits either. Yeah. You cannot use that. You can extend other interfaces. So if I have another interface up here, call it, I don't know, type. I'm just making that up. Okay. So I can extend that type up here. Species extends type. Okay. As you can see, we use the word extend just like a class extends another class and so on. But so if I have another one here, let's call this type A and we have another one. Come on. Phase type B. Okay. So I can extend both of those, just put a comma here, type B. Okay. Usually you cannot do that in a class. So interfaces, you can extend multiple interfaces if you want to. Okay. And as you can see, I just did both of those. Now, because there are interfaces, you cannot create objects out of those. So I cannot go down here and say, you know, S is new species. Or any of those interfaces out there, you cannot do that. It will have an error. It will say you cannot instantiate object out of that. Okay. In order to use these, or in order for these to be useful, you must extend these through either a concrete or extra class. So here, if I want to use these species, I will have a class called maybe animal. Right. And that can extend. I mean, it's not extend, but that can implement the species class interface. And then now as soon as I do that, you see a red line. If you must, all of that will tell you, you must declare abstract or implement these methods called get age and get name. Two options again. If you don't want to implement the functions, you must declare this as an abstract class, like in the previous video. So now without this line, then these are okay, because whichever class that needs to create objects and uses these must implement these two functions. Okay. So that means this class, if it's a regular concrete class, it must implement that. So that means you must recreate this again inside here. If I go in most of that and let it do it automatically, just say yes. You see that these two are now created inside, implemented inside this function in this class here. And then now because the animal is a concrete class that can extend or create object out of the animal class instead. Okay. So everything's okay here. So you can see the interfaces are used just to provide the definitions of functions. And they don't implement, provide implementation. You let the subclasses do their job. Why do you need this is probably a question you want to ask. Well, if you have a series of functions that you want to share across multiple types of programs, then you have a list of all your function definitions here. And then, you know, let them use that function, those functions, but you still have to implement them. So what's the point, right? Well, the point is because when you write a program, you have complete control of your code. Okay. You want to force other people, other users to use this function or have access only to these functions. Right. So if they want to do something else, they have to create their own. So this allows you to restrict what they can or cannot do. Okay. If you require a user to who uses your interface, then they must implement their own functions. Okay. So that's kind of one of the reasons for that. But it's also something very broad that should be shareable by other classes. Okay. So we have a class here that, you know, implements these species here. And because these are all different interfaces, and I can have another class. Well, let's do this. Let's go down here. And I can have another class here back to, let's just say dog. Okay. This class can extends the animal class. And can, I'm going to go and turn this implementation off. Okay. Because it's going to be redundant. So I'm going to turn that off. And it can also implement the species class. So the species is going to put type A and type B. Okay. So you can see that this animal, a dog class, extends another class, whether that class is concrete or abstract, doesn't matter. And implements these two interfaces. Okay. So interfaces you can implement as many as you want. But extension here for another class, you can only have one. Right. You can only have more than one. We saw that earlier. Okay. So now the dog has access to everything in the dog class and also everything in the animal class and everything in the interface class. And the only thing is that you must implement any functions in here. I didn't have it here, but let's just say that in a class, I have a function called, you know, get A or something. Okay. Then you see that now you need to implement that. So I have a class inside the B as well called get B. And yeah, that too. So for C down here, you see that you must implement those. And if you say yes, and then okay. And now everything's happy. Okay. The indication here just means the interface. You are implementing interface for A, interface for B. The up arrow tells you that it's in the class or the interface is above you. Right. So you are the child of that, sort of like that. Same thing with animal. Okay. So that is how interfaces are used. Okay. Mainly just to provide some functionality, the definition of functions. You can use them. And that's it. Some very limited stuff in here, but very, very generic functionality for your, a classic for your use. Okay. So there's nothing much you can do here other than what I showed you until you build a really complex program, then you will use these two again to, to a gather or put all your functions into one interface and you passed them around. Any questions, please let me know.