 Hey everybody, this is Brian and welcome to the 42nd Lamp Tutorial. Today we're going to be discussing comparing classes. Well, I didn't want to waste your time writing out this code, so let's just examine it real quick. We have two classes, a cat class and a dog class. The cat class will meow, which you see it echoes out meows, and the dog class will bark. Now, cats don't bark. Dogs don't meow. My daughter would argue otherwise she says that cats do bark. You can look it up on Google. I just don't care. Okay, so for this tutorial, just do it my way. Now we have an instance of the cat class, an instance of the dog class. It's all fine and dandy until we want to do something like this. And let's actually say, we're making an assumption here. What we're doing in the do meow function is we're assuming that this variable is an instance of the cat class. So what happens if we call out do meow with my cat? As you guessed, it works just fine. But let's say we goof up and we accidentally throw a dog in there. Nothing happens. Well, we have no idea why that didn't work. Now we're stuck going, well, what is the my dog? Is it a dog? Is it a cat? Is it this? Is it that? So what we need is to actually compare the objects. So first thing we're going to do is say, if is object, we're just going to echo out. So we want to know if this is an object or not. So let's run this again. So we know it is an object, but now we want to know what type of object it is. Remember that PHP is a typeless language, meaning a variable could be anything. You don't declare a type when you actually make a variable. You just say, this is a variable, assign it a value. It's called a typeless language. So what we're going to say now is, that's called t for type equal, get class. Because every object is an instance of a class. And then we're going to echo the type. So we see it as a dog class, but we want a cat class. So then we're going to say, very simply, now I do some function, please use the cat class. Else, we're just going to, you guessed it. So as we can see, when we run this again, it says it is an object, it's a dog, and it is an invalid use of function, please use the cat class. Well, let's examine this real quick. We're saying do meow, we're making the assumption this is a specific type. Is object, this is going to return true because, well, it is an object. If not, it's just going to say, not an object. So if we try throwing an integer into this, let's actually try that. Integer, not an object, because an integer is not an object. So if it is an object, then we know it is an object, and we get the type through the get class. We're echoing out that type, and then we're saying, if the type is equal to, we're looking for the cat class, then do the meow function. Otherwise, it's an invalid use of the function. So let's switch this to my cat, and let's make sure this whole thing works. It is an object, cat, and meow. So as you can see, the whole thing just works. Very important when you get into typeless language is doing type checking. When you used a typed language like C++, Java, C sharp, something like that, you have type checking automatically built into the language, but when you're using a typeless language like PHP, Python, et cetera, et cetera, you don't assign a type, you just assign a value. So it's up to you to do the type checking at runtime. That's all for this tutorial. I hope you found this educational and entertaining, and thank you for watching.