‫Okay.
‫So now we have a couple challenges.
‫So two challenges basically just doing what we've been looking at.
‫So you're going to create a class and create some properties and methods and so on.
‫So I'll just go I'll go through the challenges first.
‫And then you can pause the video and try it out.
‫So the first one you're going to create a class called article that has the following properties title
‫content and published.
‫The publish property should be private and have a default value of false.
‫Create a constructor that takes in the title and content as arguments and sets the values of the properties.
‫Create a method called publish that changes the value of the publish property to true.
‫Create a method called is published that returns the value of the publish property.
‫Remember, it's private, so we can't access it directly outside the class.
‫Number six create two instances of the article class or object and call the publish method on one of
‫them, which should set the publish property to true.
‫Then call the is publish method on both articles to see if they are published.
‫All right.
‫When you echo out the result of the is publish method, you can wrap it in a var dump or var export
‫function to see the actual true or false value instead of just 1 or 0.
‫So that's the first challenge you're creating.
‫Just a regular class with some properties and methods and then instantiating it.
‫Challenge two you're going to create a class called String Utility that has the following static methods.
‫So this is going to be static shout which takes in a string and returns returns it in all uppercase
‫with an exclamation mark at the end.
‫Whisper that takes in a string and returns it in all lowercase letters with a period added to the end.
‫Repeat takes in a string and a number, and returns the string.
‫Repeated the specific number of times, and uses a default value of two for the times parameter.
‫Okay, then you're going to create a new instance of the string utility class and call each of the methods
‫on it.
‫I shouldn't say create a new instance, because we're not going to use the new keyword, so you're not
‫instantiating it.
‫You can use the class name directly.
‫So I should actually change that.
‫And then for hints you can use string to upper string to lower.
‫And you can use string repeat to repeat a string a certain number of times.
‫All right.
‫So those are the challenges.
‫You can go ahead and pause the video try them out and then come back.
‫All right.
‫So I'm going to jump into these two files I have index.php which will be for challenge one.
‫And then string utility will be for challenge two.
‫So let's kind of want to see these at the same time.
‫What if we do this.
‫Yeah let's do that.
‫So we want to create a class of articles.
‫So let's say class article.
‫We want to create the following properties.
‫Title content is published.
‫So let's say public and we'll have a title public.
‫And we'll have.
‫What is it?
‫Content.
‫And then the published property is actually going to be private.
‫So yeah.
‫Published.
‫All right.
‫So that's the first and then end to the second as well.
‫Oh it should have a private it should have a default value of false.
‫So we're actually going to set a default value here to false.
‫All right then we want to create the constructor.
‫So that's going to be double underscore construct.
‫Okay.
‫I'm sorry.
‫We've.
‫Public function construct.
‫All right.
‫And then let's see the constructor takes in the title and the content.
‫So it's going to take in title.
‫Content so that when we instantiate the object, we can pass that in, and then we want to set it to
‫the properties.
‫So we use this title.
‫Set that to title.
‫And we'll do the same with.
‫Content.
‫Set that to content.
‫All right.
‫So create.
‫Method.
‫Publish.
‫That changes the publish to true.
‫So let's do that.
‫Let's say public function.
‫And we're going to call this publish.
‫And we want to then set this, and then we want the published property, and we're going to set that
‫to true.
‫Okay.
‫So that is this one.
‫Number four create publish.
‫That changes value to true.
‫Then we're going to create a method called is publish that returns the value of publish.
‫So let's say public function is published and we want to just return.
‫This.
‫This published okay.
‫Because remember this published is private.
‫So we're creating this getter function or getter method to get that value.
‫So then we want to create two instances of the article class I should say two objects.
‫Two article objects.
‫So let's say article one set that to new article which takes in the title and the content.
‫So I'm just going to say my first post for the title.
‫And then we'll say this is the first post for the the content and we'll just copy that down.
‫Let's change this to two.
‫We'll say my second.
‫Post and this is the second post.
‫Okay.
‫And we can do a var dump to check out.
‫Let's say article one.
‫So if I reload, you can see we have the title, the content and the published property, which is false
‫because we set that to false to begin with.
‫Now we should be able to call the the publish method and that will change that to true.
‫So let's do that.
‫Let's go right here and let's say article.
‫Article one and we want to call publish.
‫And now if we do a var dump.
‫You can see that the value is now true.
‫Now challenge two.
‫Let's go to the string utility PHP.
‫And when you're creating a class in a PHP file, the convention is to have the file the same name as
‫the class and do pascalcase.
‫So you want to start with an uppercase just like the class name.
‫All right.
‫So I'm just going to open that up or open it up in the browser by going to string.
‫Utility, which you would usually never do.
‫Go to a file that is just that is a class.
‫This would be like in your your lib folder or something like that.
‫And you would then include it into another file to use it.
‫And we'll get into that when we get into our project.
‫So let's start off let's say create a class of string utility.
‫So let's create our PHP tags and then class of string.
‫Utility okay.
‫And then we want to create three methods.
‫The first is going to be shout and it's going to be static.
‫So let's say public static function.
‫And it's going to be called shout.
‫And it's going to take in a string.
‫Okay.
‫And then all we want to do is return that string all uppercase.
‫So we can do string to upper.
‫And then pass in.
‫String.
‫And then it says to add an exclamation.
‫So I'm going to just concatenate onto that an exclamation.
‫All right, so the next one is what?
‫Whisper.
‫So let's say public static function.
‫Whisper takes in the string.
‫And we're going to make that lowercase with string to lower pass in the string.
‫And we're going to add on concatenate on a period.
‫So that's our whisper.
‫Then let's say public function.
‫Public static.
‫Function.
‫And this one's going to be repeat.
‫Which is going to take in the street.
‫It's going to take in the string, but it's also going to take in.
‫The number of times.
‫And it says to set the default to two.
‫So we're going to say equals to like that.
‫And then we can return and use the function str underscore repeat.
‫And that takes in the string and the times.
‫All right.
‫So that should do it for our class.
‫Now to use it we can come down here.
‫And let's do echo and remember their static static methods.
‫So we don't create an instance.
‫We just use the class and then we use the the scope resolution operator.
‫So let's call shout.
‫And let's pass in.
‫Hello, world!
‫So if we do that, we get Hello World in all caps.
‫Now I'm going to copy this down and let's try whisper.
‫So if we do whisper, then it's going to be in all lowercase.
‫Okay, now for the repeat.
‫Let's say echo.
‫Echo string utility.
‫Repeat.
‫And let's pass in.
‫Hello world.
‫And then we're going to pass in the number of times we use five.
‫Let's reload.
‫And we get Hello World five times.
‫And if we don't pass in a times argument, it will be two because we set that that default to two.
‫All right, so that's it.
‫In the next video we're going to look at something called abstract classes.