 Okay, welcome, welcome. Today, I'm going to be doing a lot of this at the beginning because I'm gonna be standing on my computer due to some coding in a little bit and I don't like to get stuck behind the podium there. Not a lot of fun. We're gonna try to make this a lot of fun and interesting. Hopefully, you will all gather something very important from it. I've been told I'm going to throw out t-shirts. This is a great way to do it. Everybody likes to get t-shirts thrown at them, right? So, the t-shirts that I'm throwing out are fitted shirts. All you need to do is bring them up here and exchange them for the correct size. I'm just throwing these out because they're already bundled together. And then you can come and choose whichever size you want. Smallest here to the largest on this end. These are my fitted shirts for anyone who would like them. So, this is the way it's going to work. I'm going to share some things about object-oriented programming. We're going to discuss ideas. We're gonna get into some code and see how it actually works. I'm going to ask for suggestions from you on how we should modify this code to see what happens. We'll get to play around and see what actually happens here. I spent the first two days of my trip in Bath and I met a really interesting older gentleman at a pub and he worked in the travel agency in the 1970s and they switched over to a new computerized system and he said, you were the first software engineer that I've ever met that's actually interesting. He says, they were so boring. They talked to us about all this new thing. It was so boring. It's the worst, worst experience ever. We all hated it. For the same travel agency and said, we didn't all hate it. But he thought they all hated it because it was so boring. So, they get to launch day and a huge big deal. They're ready to celebrate. This has been like a year in the making. And all of a sudden on the screen, it says, DFP. No one has any clue what DFP means. In all of their training, they have never seen DFP. Nobody has ever said what DFP is. Running through the manuals, trying to figure out what the heck is this? Because we're supposed to launch this. We've got the call center ready to spin up to accept calls. What's going on? And it was a joke from the programmers that meant don't effing panic. And it, sure enough, it turned back on and they were able to use it and they were not amused. But all of that to say, hopefully we have this a little bit more entertaining. Hopefully you enjoy it. And in so doing, you actually gain some knowledge. So, I've been working in PHP for 17 years. So, when I started, PHP was completely procedural. There was no object oriented. So, object oriented comes to the market and I decided I should learn object oriented programming. This is a great new idea, right? And I went, am I just stupid? I just could not, it just didn't make sense to me as I was trying to learn because all these new ideas were coming out at the same time. Now that we have object oriented, we can come out with frameworks and we come with, now we talk about all these design patterns and all this stuff that surrounds object oriented and kind of just gets grouped together. And you have all of these things to untangle and go, well, what are people actually talking about? Why are we actually doing this? It was a great thing. Procedural, there's nothing really wrong, per se, with procedural code. The issues come into it when, as it scales, a small project is sometimes best in procedural code. It can be easier to manage, simpler to debug, easy to get a handle on. The problem lies in the way our brains work. There's only so much information that your brain can handle at one time. You've all heard of short-term and long-term memory, right? Okay, this is, I love talking about the brain, but we're not gonna get into that. Short-term, long-term memory, the big thing about this is you've got somewhere between four and six pieces of short-term memory that you can hold in your brain at one time. How many of you have systems that have more than six parts? Okay, therein lies the problem. You can't store all that in short-term memory so they can't all function together very well. So with object-oriented program, we can put it into chunks. This allows us to chunk these things and we don't have to know all of these chunks at the same time. So when things are encapsulated, as one of our terms will be learning soon, nicely we're able to hold chunks of data, more data, but in chunks, and just the chunks that we need to be able to process that and put it to good use. So I'm not saying you always have to code an object-oriented code. You will probably run into object-oriented code. Is there anyone in this room who has not actually used object-oriented code? Okay, very few. And that's okay. After today, you let me know if you're still having problems with object-oriented code because it's really not as complicated as it seems. Okay, so you're gonna run into it, you're gonna wanna use it. It's gonna happen. If you're writing code by yourself in a bubble and you don't ever want to use any add-on packages, then you're probably okay sticking with procedural and not learning. So that's why we're learning this. So let's go through it and see what we have. To me, the most important part is terminology. Terminology is very important because you can't Google if you can't read the words or you don't know what to ask. Google has all the answers, but if you don't know what to ask, it's not very useful. Or if you ask a question and you get back an answer and you can't understand what they're trying to tell you, again, not very useful. So the biggest thing I want you to gain out of this talk is to understanding what the terminology is. So when you go to use it, you go, oh, this makes sense. I can now actually find answers. So part one terms we're gonna talk, this is very basic object-oriented terms that you'll see. Classes with their properties and methods, objects and instance. We're then going to get into abstraction, a lot more difficult words here, encapsulation and scope. Finally, we're going to get into polymorphism. Another big words. I love how object-oriented wants to put in all these big words that sound really complicated and make you feel like you're never gonna get it, but they're really not very complicated terms. So once you understand what they are and how they work, hopefully it will make it seem a lot more accessible. So in polymorphism we have probably some things that you've heard, inheritance, interface, abstract class, traits. You've probably heard of people talking about these things. Maybe even wondered what the heck they are. Well, hopefully today we'll be able to clarify that for you. And then there's some extra fun stuff that we might not get into in this talk and some things that object-oriented classes now let us do. Static methods, magic methods and constants. I love magic. Namespaces and type declarations. So I've got some examples at the ends. All my slides will be online. I have example codes. So even if we don't get into all of that today, there's some stuff that you can take home and get a little more into once you understand how objects work. So to get started, we wanna make sure that everybody is on the same page here. A class. A class is simply a template or a blueprint. How many of you have ever built Lego before? Good, most of you have done it. Okay, my son is five and his favorite thing right now is Lego. For Christmas, all of a sudden he got really big on the Lego and he loves to be able to follow the directions and put the Lego together. And he's just starting, he's done like probably 10 different sets following the directions and now he's starting to get to the point where he can really have fun and realize, oh, now I can put these together and make my own stuff even better. But we need this template or blueprint to start with. This is how you build houses, right? You can't, it's, they don't let you build houses without a blueprint anymore. Just doesn't usually work as well. So templates, blueprints, very important in everything, recipes, following a recipe, especially when you're learning, very important. These are what, this is what a class is. It's just the template. Tells us what we're gonna, how we're going to build something. It's a combination of variables and functions. So if you've written PHP before, which I hope you've at least done something if you're here, you've dealt with variables and functions and a class will just allow you to put those variables and functions together. So the object is what is created from that class. So if you were building a house, blueprint of the house, someone would then build a house from that blueprint. So the house itself would be the object. And this now consists of actual data and the procedures. So the paint color, how the door works, turning on and off the lights, opening and closing the doors, those types of things, the important parts of how it actually works, part of the house itself. Now, an instance is a particular object. So for instance, if our class was DNA, DNA makes humans, which would be our object, and each of you would be a specific instance of that object. So it would be a very specific instance of an object itself. And just like with people, we give them certain names so we know which specific object we're referring to. Do we have anybody in here named James? A couple of people named James. Okay, so if you were in a group of people all with the same name, or you have two Johns on your group or whatever, so it makes it really difficult to refer to somebody if there's six Johns in the room or six James in the room. So you need some way to distinguish. That's why we get nicknames, Jim, Jimmy, Jimbo, whatever. We make up nicknames so we know who we're talking about. Sometimes last name, sometimes people just go by their last name, but that's a reference for us to refer to a particular person so we know which person we're referring to. That's what an instance is. It's a specific reference to an object, to a specific object. Okay, so this is what it looks like. We're gonna go into the actual code after the next part. So this is what it's actually gonna look like, though. This is the actual code here. We have a class. Our class is a user class. We have a property, which is our variable named name. We have, oh, you cannot see this one at all. Mine is much better. And then we also have a function, which inside of a class is called a method. It's still, you still call it as a function. It's still named function when you write it out. It's just called a method inside a class. Again, it's one of those naming things that helps us know what we're talking about. So then we call our users. So we have user one and user two, and those are our specific instance of the object. This is all very basic stuff. How many of you are still confused about this basic part of objects? Everybody feel like they have a handle on this basic part? You're going, okay, I'm bored now. Can we move on? Something interesting? Okay, let's move on to something a little bit more interesting. Now we get to some big words and what these actually mean, abstraction. Okay, our first big word we're gonna talk about is abstraction. So why is abstraction good or is it good? So abstraction hides all but the relevant data about an object. This reduces the complexity. Again, I said you can't store everything in your head. So you can't store how every single piece of your project is going to work. So you need to be able to understand a little bit. So all I really need to know about an object is what information I need to give the object and what I expect to get back. It makes it a lot easier when dealing with that object. I don't need to know how it works. It's just like using my computer. I don't need to be able to write the operating system on my computer. I don't need to be able to put the hardware together on my computer to be able to use it. I don't need to be able to build a car or even be a mechanic to drive a car. I just need to know what input I need to give it and what I expect to get back. That's what abstraction is. So using something without knowing the inner workings. Encapsulation, all this means is it's together. So instead of having to track your data in one spot and what you can do with that data in another spot, it's stored together. So it's easy to move that piece of information around together, your data and your actions that you can perform on that data. Those are your variables or in a class it's called a property and your functions which inside a class are called a method. So when talking about these things the important thing to know is scope. Your scope is like your guard who says who can access what? It controls what access people have or your script has which portions of your script have access to what? So this is another great feature of using object oriented design. You can make sure that things only come in a specific way that you only accept certain things from certain people, certain groups, certain functions. You can control a little bit more what happens. So you can make it public to anyone. We're gonna get into some code and see exactly what this looks like. Public to everyone, protected, which means children of that class which we will get into in a little bit. And then you have private which means nothing outside of the functions of your class, your methods, nothing outside of the whole class will be able to access it. So you have to have some way to get that information out or be using it within your class but you can't access it from outside your class. So great, our first live coding demo. Oh, there we go, let's see. These are my kids. Okay, can you see it back? Can you see it in the back? Yes, no, I don't hear anybody yet. You're not in the back. Okay, so my front row is getting all the t-shirts. I guess I don't need to have a very good arm today. Okay, so I hope that you can see this and I'll just trust that you can. We have our user class here. We have a public name, a private title, some methods which are our functions that you see here and this is our class. This is our blueprint for how it's going to work. So we're going to call this in our index file. My first require here, oops. Okay, my first require here is just to make our page that we're gonna look a little bit bigger and nicer to see, handle some errors for us and then we're requiring this user class that I just showed you. Now from here we're going to instantiate our object. We're creating a specific instance of an object class. So we have our user and we set the name and then we've used our method to set the title. So the first thing I want to do is show you what this looks like. So this is what it looks like. James Smith, because here we told it to get, we set the name, set the title and get salutation. Okay, so why am I setting these differently? Well, first off, this one is setting the name directly and that works. So if I wanted to do user title and instead I want to set this equal to Mr. Okay, now, we can't access the private property title from this file because our property was private. We can't access it from outside the class. So we try to set it directly and we can't access that. So that's why you see here we have this set title method. Now the method is public which means I can access the method from outside the class and then the class can set the property itself. Can anybody give me any ideas of why we would want to do this? Why this is even useful? Sanitation, there we go, who said that in the back? Yeah, I don't know about that. Yeah, not that good, I can probably make it about halfway down this back part here. Okay, so yes, sanitation is important. It's over the back. Okay, so sanitation is important. So if I want to accept user data, we need to make sure it's in the right format. How many of you have ever dealt with dates? And you have some dates written even the days of the week. Somebody has put them in as Wednesday and somebody else has put them in as wed or months or states or pretty much anything that people decide to put in. Capitalization is off, spelling is off. All kinds of formatting can be different. How many of you have ever tried to look for a specific day and ran into this issue? Have you ever had any problems with this ever before? No, nobody's had. Well, I guess we should all go home now because nobody has ever had to deal with any issues on user data and you guys all have fantastic users that know exactly how to input everything. Then your job as a developer has been smooth and perfect. Please come and talk to me about where you work because I would like to work there with your users. So for the couple of you that may have thought this might apply to you, this allows us to control what happens. Control what comes in. No, that's not how I want it. Or can I take this data that the user gave me and reformat it? For instance, do I just need to capitalize the first word? Do I need to run this against a sample of data so I can say if it came in as an abbreviation I can turn it into the full name that I know it's supposed to be. So these are different things that we can do. So let's try this. Okay, so as you can see here on this set title, let's see, I'm going to change this to just lowercase. Okay, so we'll see how this works. If I just did it just like this and now I see that my title is now lowercase. Well, that's not the way I want it. So we could either change it on output or we can change it on input. Well, it's much better for the sanity of your data to change it beforehand when it comes in. So we go back into, there we go, user, and we set our title. And we say that we want our title to be UC words. There we go, let's go back here. There we go, very simple, but you can see how this could be used in a much more complicated schema if I wanted to. I control what happens as it comes in, how the data gets stored, what I do with that data. Okay, so let's see. I want you guys to give me a little bit more participation here. So we're going to change something in here. Give me something else that we want about our user. What other data do we want to store about a user? Date of birth, okay, we're going to get right into security issues here. Okay, so date of birth. We're going to set this up here. Now what do you think should our date of birth be public or private? Private, yes, good point. Should be private because we're working with dates and everybody loves working with dates. So our private date of birth. And then we still need to get data into and out of our object. So that's why they have what they call getters and setters. How many of you have heard of getters and setters before? Okay, so that's all that this is referring to is the fact that if I have a private variable or property, I can't set it directly. So to access it, I need to have a method that gets the information and sets the information. Getters and setters. So you will see a lot of getters and setters and we've demonstrated why. So let's go down to here and we'll say public function DOB, we'll do it this way and say DOB. And all we're going to do is say this DOB. Okay, who can tell me what this keyword stands for? The specific instance. Yes, since I don't know what the name of this instance is, I can still reference it in my class by calling this. So if I've named this James, and I now am using James as my object, this essentially means James. So just like if I were outside my class, I would reference it as in our last one we had user one. Remember that? Yes? So it's just like saying user one DOB. But I don't have to use that specific object name, it's whichever object is in the class. So there we go. So we have our setter and public function get DOB. We don't need that. Return this DOB. There we go. Okay, so to use this, oops, wrong one, we're going to need to user set DOB. And I'm just going to say second, 2018. Foundation, this is a valid date of birth right now. I am born next year in January. And as you can see here, probably all of you from the UK are going to put her dates in wrong. The two should be before the January. Yes, okay. And obviously a date of birth should not be before today, although it shouldn't be any later than nine months out, probably eight months out because you shouldn't know you were pregnant and you could put it, okay. So anyway, we can get into a whole discussion of which dates are valid and which dates are not. How are you going to use it? Dates again, nightmare to work with. But as you can see, if we have a setter, we can actually program that somehow. If we don't have a setter, this date is valid. So we're going to say that is my date. I could run something against this like checking that date. Oh wait, I don't have any validations. So I wouldn't know how to turn this into an actual date object. So I guess all I'm going to do is echo it out. How boring. If we could turn this into a real date object. Now I could say, is this the second of January? Then I could say happy birthday. But since I can't, we're just going to say, get the OB. Okay, and if you'll notice on my methods or my functions, they end with the parentheses. If I'm calling a variable or property within a class, they do not end with the parentheses. If I'm calling a method, it does. Technically, it's not needed most of the time. But it's still a good practice to do. If you're calling a method, this helps you know right off the bat, this is a method and not a property. So let's go see how this worked. Look at that. We have it all jammed together. Let's go like this. Oops, there we go. It helps if you copy the right line. It also helps if, like, there we go. Let's see, this one, this one. Okay, there we go. Woo! Congratulations, you just helped us write our first new property with getters and setters. Good job. Okay, let's learn. Everybody ready to learn a little bit more? Yes, yes, yes. Please, please, please. Okay, so now that you understand why we have abstraction, right, okay, who can tell me why we have abstraction? These are our getters and setters. This is the information about this class. Why do we have abstraction? What does this allow us to do? Change the type of, it gives us control. It's all about control. The person programming this class can have the control. And the person coming in to use it doesn't need to know how it works, okay? This is great, this is good for everyone, yes. Yeah, so you need to tell, they need to know how it works. So you'll need to tell the people who are going to access this class that should be what your documentation is for. So documentation right off the bat should tell that's what the documentation for a class should be. It should tell you what information goes in, what type of information goes in, and what type of information goes out. We can get even more precise with that with type declarations, incoming and outgoing type declarations. So that's cool, but that's what you need to know. I don't need to know what happens on the inside. I just need to know what specific information I need to give it and what information I can expect out. But I need to know how, what do I need to do? What can I give it? I need to ask for the get name. I don't need to know what that get name does. I need to know that I can ask for the name. So yes, some of it, so in a way, you need to know what methods are there, but you don't need to know how the methods work. Again, it's what you put into the method. Do I need to give this method any data or just call the method and what do I get out? But again, you do need to know what to ask for. Just like with terminology, you need to know what to ask Google. Google can give you the answers, but if you don't know how to ask, it's not very useful. Just like if you have a class that nobody knows how to use, it's not very useful. So you need to make sure that they know what to put into it and what to get out of it. Okay, there it is. Okay, back to our next fun part, polymorphism. Okay, how many of you have ever been scared away by this word? I feel so alone. I'm the only one. Okay, so polymorphism, another big word that I'm bleeding all over the place. Polymorphism means simply ask for something, get it back in a specific way. So polymorphism is actually sharing code. Okay, so this person is asking, now speak. We're getting all the animals are speaking in their own language, right? Okay, polymorphism is all about sharing code. It is not specific to programming. There's polymorphism all over biology, genetics, biochemistry, computing, and it all means essentially the same thing, it's just sharing of data. So in programming, and especially in PHP, specifically, we'll talk about inheritance, interface, abstraction, and traits. These are all ways to share code. How many of you like writing the same thing over and over again? I don't know. I'm guessing you all do, because this is the response I get to each question. So I'm gonna say that when you don't raise your hand, it's a positive reaction. So you all like rewriting code, okay? So I'm sorry that maybe we'll make this a little bit too easy for you. Sure. A Band-Aid might be better. Cracked knuckles, I have very dry skin. Okay, so we're sharing code. That's all this means is sharing code. You've probably done this, if you've written procedural code, you've written a functions file, and you've put this in a nice place to organize your code, you know how to organize your code and share those functions with other files. This is great. It's a great way to do it. So object-oriented just gives us a couple different ways to do that, but the whole point is to share the code. Depending on how and where we need to share it, we'll depend on how it's actually used. So let's talk about inheritance first. Okay, how many of you were ever born? Thank you! Finally, something actually that got you to raise your hands. Okay, so inheritance. You've probably all heard this referred to when talking about a parent-child relationship, grandparents, you know, hierarchical things. It's inheritance, right? You've heard this word referred to before. Is there anybody that has never heard this word referred to before? Okay. And it is. It is the same thing. Again, we haven't made up new words or changed the meaning of words in programming. It's the same thing. We're passing information down in a hierarchical scheme. It's passing information down just like as my blue-eyed son got his blue eyes from neither his father or I, but from further up in the chain. And each of my children, three children have different colored eyes. Well, that came down from somewhere. Somewhere in the past, it's been passed down those genes. Maybe not directly, and that's sometimes where the confusion even gets with your code. So when you are programming inheritance, it comes down in a straight line. So this class inherits from this class and this class alone. It can only inherit from one class. However, this class could inherit from this class, from this class, from this class. So you can make a long chain. Ideas are really helpful when dealing with this because they will help you track down the chain. But that's how inheritance works. One down, down, down, down. And it passes information down. You can pass properties. You can pass methods. You pass them down, but only as one. So let's go into seeing how this works. Cancel that. Here, okay. So we're going to make... There we go. So I've created a new class called developer. A developer is going to be a type of user. So we're going to extend a regular user because I like to think that as a developer I have all of the normal skills that any user would have plus extra development skills, right? Okay, so this is how it's going to work. Awesome, thank you. So I have my user. This should be fine. Thank you. Okay, so can you... Yeah, you guys can see. Okay, so as you can see here, we have our class developer and extends user, but it doesn't say anything about name, right? Do you see anything here that says anything about name or title? No, okay. So let's go back to... Here. And we're going to create... We're going to call our new developer. So this is actually still a user, but I'm going to name this James. I'm going to pick on James. So this is James. And he's going to be a new developer. Okay. Now, James needs a name. Okay, well, I'm going to set a name just like I did up for James Smith. I'm going to say James. There we go. Okay, and then we're going to try echo. I'm actually going to say... Oops. Ha-ha, I see. I see it. And get salutation. There we go. Okay, I'll go back. Line before there. Look at that. See? Live coding the pressure. Okay, there we go. So, if I had left it as user, it would just reset my user, and James would have no name. So, here we go. We want the gate salutation and James. Okay, so let's see what happens. Oh, live demo. Class developer not found in file. Okay, so, as you guys already saw, because you were so smart and such a... such a paying attention crowd here, we saw that we need this to require our developer. Okay, now let's go back here. Play it again. There we go. Okay, now, I was able to... Okay, let me finish what I'm doing here. I was able to set the name and call the name of my developer, even though my developer class didn't have anything about a name property. This is because it inherited... This isn't because it inherited all... it inherited all of that from the user class. So, everything that my user could do, my developer could now do. But now we have some extra things that the developer is able to do as well. Okay, so, in here, I have that my developer... There we go. My developer has skills. So, I'm getting skills, setting skills. I'm getting a skill string, and I can add a single skill, or I can add it via setSkills as an array. So, you'll notice my setSkills is wanting an array, and my addSkills is wanting a string. These are type declarations we'll talk about in a little bit. But they're there so you can understand a little bit what's going on, which is another really handy thing is that you'll come along to read your code. They know this is what it's supposed to be accepting, especially if your code gets a little more complicated. So, I can either accept skills as a string by using the addSkill or as an array by using setSkills. So, let's go into... back here, and we're going to set some skills here. Okay. Okay, James. And then we can say, setSkills. Up, James. SetSkills. And then this is an array. So, here's my array. What kind of skills do we want to give James as a developer? Beard growing? Okay. A lot of developers have very interesting beards. Beard growing. There we go. Okay, what else? Does he know any languages here? Zend framework? Okay. I'm going to assume maybe we'll give him PHP knowledge? PHP? Okay. So, there we go. We've got... we've passed some skills to him. Echo. James. Get. Skills. Again, IDEs can be very useful for this. Okay. So, let's go here and see. Array to string conversion. There we go. Ha-ha. There we go. Beard growing. Zend framework and PHP. Okay. So, we have... we now have our... we now have our user. We've extended our user as a developer and we've been able to add new features to our developer, as well as use all of the features already accessible by our user. Okay. Let's go back and see what other polymorphic activities we can accomplish. So, the next thing we have is interface. So, an interface, again, how many of you have ever dealt with building or remodeling a house? Okay. You have regulations. Okay. You have regulations that you have to follow or it won't be approved, right? And you can get into trouble. It can cause problems and delays if things don't work right. So, there are regulations to follow. So, the interface is essentially those regulations telling you what is allowed for a particular type of object. So, if you're going to be building a house, you need certain things. You have your fire codes. You have your, you know, how big doors have to be and how wide things have to be and all of that stuff. Okay. So, your interface is that. It's telling you the requirements. So, for an interface, you can have multiple interfaces. This is the nice thing. I can know that I can have an interface that talks about a user being a developer being a person. So, there are certain things I need to know about a developer as a person. There are also certain things that I need to know about a developer as a teammate. There may also be other things that I need to know about a developer as a citizen of a particular country. So, I can include interfaces with, that have different requirements in each of them into one class. So, this, so now I can group those apart so that this class might only use this interface where this class uses three, but it gives me a way to kind of break that up a little bit and use what I need where. Again, remember how we started, we could only have one, inherit down one class this. Now I can use as many interfaces as I want. All methods are public because we're just telling them requirements so we're not inheriting anything so they actually need to implement this. They need to know about it. Those implementing it need to know about it so it has to be public or protected. It can't be private. Let's put it that way. And it may contain a constant that cannot be changed. So, let's go back in and see what this looks like. So, in our code, we also have... There we go. We have a toolkit... Oh, that's my trait, sorry. I have my interface. There we go. User interface. Okay, here's my user interface and it says that I need to get a formatted salutation, a git name, a set name, a git title and a set title. Okay, let's apply this to my user class. Implements. User interface. Okay, now let's see what my code says. Oh, yeah, it's the fatal errors. Can't capture them so well, but it says there's a fatal error. So, let's see. Okay, here we go. You can see this class must be declared abstract or implement methods, git name and formatted salutation because I don't have those on here. That's what it's telling me. I don't have these, it's not valid. So, I need a git name. Which, what? Oh, yes, there is. Okay, I can just do it actually this way. Can I just click on... Is that what it said? What you were saying, F1? Alt, enter. Okay, there we go. It's our git name and git formatted salutation. So, I need to... I actually just want to call right now. I'm going to return... return this. Get salutation. I could do more to it if I wanted to, but we're not going to now. And then we're going to say return this name. Okay, now let's go back here. Yes, we do need to require this. Require... user... user interface. There we go. Okay, there we go. Okay, now it works. And we were prevented from creating a user that didn't have the specific details that we needed to use. So, if I want to allow people to create, instead of just inheriting a user, but I wanted them to create different user types, but they need to have certain things. This is how PSRs are adhered to. You say, here's the interface for how this PSR needs to be implemented. And you can include that, and you can write it any way that you need to, but it needs to have these certain methods so everybody knows how it works. I know that I give it certain information, and I expect certain information back. So, this is a great thing for that. Let's go back to here and see what else we have, our abstract class. Okay, so the difference between an abstract class and an interface and inheritance. So, abstract class allows you to combine the interface and the inheritance, because you can put... you can tell it to have an abstract method that says that the child of this class must implement that method, just like we did for our interface, but we can also include a method that's already done, just like we did from inheriting a class. Classes extending an abstract class must implement all the abstract methods defined in the abstract class, because they're not set up yet. A method it hasn't been defined. Just like in the interface, we didn't define how it worked, so our class still needs to define how it works. So, let's see that. Okay, so, our abstract user here. Here's our abstract user, and as you can see, the abstract user has a get name, a get title already set, and then it has down below the abstract set name and abstract set title. Those have not been defined how they work. So, therefore, my abstract class, so that my class that implements my abstract user will need to make sure that it defines those. So, let's go back. Oops. Let's go back into user. Oops. User. Require. Abstract user. And implements and extends. Oops. Just like extends. It has to be before. That's what I was thinking. I usually... Oh, thank you. Extends. Abstract user. And there we go. Okay. So, we're still having it. Title must be public. Okay, so, if we go back down here, as you can see in my abstract user, it's saying that my title is public. So, that's what it's requiring because I've made that an abstract class. If I didn't want it to be... I can put this in here. It still works. And my abstract class does not need it because I can't call my abstract class directly. So, I can't call an interface directly and I cannot call an abstract class directly, but they can be used to help me know how a specific class or type of classes has to be implemented. Does that make sense for people? Yes. Okay. Let's go back here. Do-do-do-do-do-do. And... Oops, there we do. We did that live demo. Traits. Traits. Okay, I'm going to touch on this. I'm not going to do this too much because people don't like me to do this because people get really nervous about using traits because traits have this great feature of being able to include any traits you want all over the place anytime. And it's just like includes. How many of you have found includes all over the place and made it really hard to track stuff down? It's just including something here and something there. Okay. So, basically, what a trait is, is it allows you to use this trait here and as if I wrote that code right here every time. Super powerful and can be super dangerous. So, it allows you to share code like this and you can share it as many times as you want. You can put it in. It doesn't have to be once. Multiple traits can be used. I can put it in anywhere I want all the time. Use it all over the place. This can be great. It can also be very dangerous. So, let me just show you what this would look like really quick. Oops. Okay, really good at that. Let's see. So, we have our trait, our toolkit here. And here's our trait. It looks a lot like a class. It has information here just like a class did. It gives us all this information. It's like being able to add all of that to our code. Everything that's within that trait is going to get so this private tools and all these functions. So, oops. Now, if we do... Nope. Yep. Okay. So, toolkit. Okay. And then right here, we'll just put use toolkit. And I think that started with a capital letter, didn't it? There we go. Oops. So, use toolkit. Now, if we sign our toolkit, we are able to set tools. And if we pass it eat, it's going to add all of these tools. So, let's go here. And we're going to let James do it. So, James, set tools. And we want him to be able to eat. Because James likes to eat. Okay. So, now we can do echo. James, get tools. It is right there. Ah! Okay. Tools. There we go. Ready to string conversion. And I get show tools. Here's my toolkit. It is show tools. Yep. Okay. Index, show tools. There we go. There we go. He has a spoon, a fork, and a knife. Okay. So, that's how traits work. And you can use as many as you want all over the place and make your code really fun to try to track things down. So, but it actually is useful when you need to be able to store, maybe you do need to have a small chunks of code that need to be used over and over again in different places. Okay. Well, I could write it over and over again in different places. But sometimes that's the only way you need to be able to share it. Okay. So, for instance, humans, they need to use tools. There are other mammals that use tools as well. So, we need to have those same things in here. And I know my time is over. So, I'm just going to show you what the extra features are. I told you we probably wouldn't get to this anyway. So, the added features that this allows us to do. Now that we know how abstract, encapsulation, polymorphism, what these big words mean, and why we are using object-oriented code, now we have extra features that help us to make this more easy to work with other developers. These are things such as magic methods. The magic part of magic methods is that they are called by an action, not by when something happens that triggers them, not by being called specifically. They are triggered, not called. Magic constants are something that PHP already knows about. You don't have to set. You can create static methods, which means you can access some method on a class without having to create a class object. You name spaces so that when you have two classes called user, you can still call them separately, just like when you have two people called James, you have a way to distinguish those users, those people. And we have type declarations, which I showed you briefly what it looked like. 7 has a lot more than 5 as far as type declarations go, but it gives you a little bit more ability to share what comes in and what comes out, because that's what the users of your class need to know, what comes in and what comes out. So this information is all here for you. I've added this so that when you get my slides, you'll all have this here. And I also have t-shirts up here, so if you want to come and talk to me and get a t-shirt, you are welcome to come and talk to me and get a t-shirt or a bag, so if I run out of the shirt in your size that you like, you can come and get that too. Here's some resources. If you would like to learn some more, I found these very useful. Again, my slides will be shared, so they'll be here for you. And this is me. This is how you can get ahold of me. Please rate the talk. Give me ideas of what you liked, what you didn't like, how I can improve. I like to be able to share this. What's something that, if there's something that you said, oh, this finally made sense like this, or this part really just was more confusing, let me know. You can have some code examples. I'll actually put up just what we did here as well on the GitHub repository so you can see exactly what we did here. So, once I tweet out my slides, that will be there for you as well. So, here you go. Goodbye. Say hello to my kids.