‫Okay, so a while back I told you that PHP is a dynamically typed language, which it is.
‫But you do have the option for strict types, so you can either set a value in your main php ini file,
‫which is like your main config for PHP, or you can just type it right in your script.
‫So if you want to use types and this is completely optional, by the way, I just want you to know that
‫this exists.
‫You don't have to use it.
‫I'm not recommending that you use it, but there are pros.
‫There are some pros to using strict types.
‫So let's create our PHP tags.
‫And then I'm going to create just a basic function.
‫Actually, before we do that, let's let's turn the type declarations on.
‫So to do that we can say declare.
‫And then inside here we're going to say strict underscore types oops strict types and set that to one.
‫So we're turning on strict types.
‫Now let's create a function.
‫And we'll just create, let's say get some.
‫So just another add function that takes in a B.
‫And then returns a plus.
‫Be.
‫And then we'll run that.
‫Get some.
‫And we'll pass in one and one.
‫Okay.
‫So if I we're going to have to echo this out because I just returned the the answer.
‫All right.
‫So we get to we get no errors.
‫It's fine because because this is optional.
‫The types are optional.
‫But if we wanted to make our code a little more robust, what we could do is say that this this this
‫a parameter or the argument that gets passed in here has to be an int.
‫And we can do that by just prefixing prefixing it with int.
‫And same thing with this b that should also be an int.
‫And then the return value should also be an int.
‫We can do that by putting colon int here.
‫All right.
‫So now if I reload this is going to work.
‫However if I were to change this one that I'm passing in to a string then it's going to give me an error.
‫It says expected type int found string.
‫And if I reload the page same thing must be of type int.
‫So it's going to break my code if I put the wrong type in.
‫So you can see how this can make your your code more robust and less prone to errors.
‫Now if I don't have this declare here, then that's fine.
‫That's going to work.
‫But this line is making it.
‫So if I say that this has to be an int, then it has to be an int.
‫Okay.
‫Same thing with the return value.
‫So even if I pass in here.
‫Ends.
‫But then let's say let me just comment this out and let's say a return a string.
‫That's going to give me an error.
‫And you can see now this has a red line under it expected type int found string.
‫Because I'm returning a string.
‫And that's not going to work either.
‫Okay.
‫So just just an option if you're coming from a language like Java or C plus plus any other language
‫that has strict typing, then you might feel right at home with this and you might want to want to do
‫this.
‫Just to give you another quick example, we can do function.
‫Greeting.
‫And let's say this has to take in a string so we can say string and then we'll say name.
‫And this has to return a string as well.
‫So string and we'll return.
‫Say hello.
‫Name.
‫Greeting John.
‫And we got to we got to echo that.
‫And there we go.
‫Hello, John.
‫Now, if you wanted to echo in here like this, then we don't have a return value.
‫So what you would do for the return is use void.
‫Okay, so if I do that, then that works.
‫Void just means that there's no return value.
‫And here there isn't.
‫I'm just echoing something out.
‫Now, if you want to learn more about type declarations, I'm just going to paste the link in here to
‫the documentation.