 Hey everybody, this is Brian and welcome to the 35th LAMP tutorial. Today we're going to be discussing the const statement and the scope resolution operator. So let's just make a class called myClass and we're going to add a function in here called test. All right, now we've seen this 100 times before. Now we're going to make an actual constant and we're going to say this is, we'll say maxUsers. Just a generic example, we're saying maxUsers equal 100. So the maximum number of users in any given thing is going to be 100. Notice how I did not use a dollar sign. I think PHP is the only programming language that actually uses a dollar sign. But when you create a constant value, much like my cat's constant now, I don't know if you can hear her begging for my attention. Cat, you totally just ruined my chain of thought here. Anyways, constant value doesn't use a dollar sign. Constant values can never be changed. So if we go to say maxUsers equal 200, notice how syntax error, unexpected equal sign. Why? Because we've already declared the value. This is different than a variable. A variable has the dollar sign in front of it and it can change. A constant can never change. Now let's see how we can access it from within our class. How would you access this? Like if we just wanted to echo it back out. Let's see here. Let's try a few things and see if they work. Do you think that you would use this? Well, then you would be wrong. It's actually called self. Now suddenly you can access maxUsers. Notice how you have the word self with double colons. Double colons. That's called a scope resolution operator. Scope resolution operator. You can find this out on the PHP tutorials and really what it does without getting into a very big, long, lengthy discussion on memory and how things are stored. I mean if you've taken any of my C++ classes, especially the cute classes, I've probably beat the scope resolution operator to death. But really what it does is it allows you to get things that are defined on the global space for that class. Now what do I mean by global space? Basically anything that is defined that exists for all the classes, not just the current instance. And what do I mean by that? Well, basically when you create a constant value, it exists for all instances of that class, not one value per class. Same thing with a static value. Now what is a static value? Well, like a constant, it exists in all instances of the class, meaning it exists before the class is even created. What we normally do is we will say, let's see here, what's called my C equal new, my class, and then we'll say my C 0.2 test. Now notice how we can access our constant. We can also access our static. But there's something special about this. Let me show you something here. Let's comment these out. See what we're doing is we've created an instance of that class, but what if we don't even have an instance of the class? Notice how we can still access those things. So we haven't even created an instance of this class yet it exists. Now what if we did something like this, public, let's call this val equal 12. Let's see if we have the same results here, echo, my class. Notice how we cannot access the val variable, val, because we need an instance of that class and that's what I'm trying to really drive home here is that constant and static live for the class, meaning they exist before the class is even created. There's only one of them that exists in memory, whereas variables, for example, this instance right here of val, one of these will be created per class. So if you have a hundred my classes, you'll have a hundred vals, but you only have one max user and one name. Note the difference between const and static. Const you do not use a dollar sign, the value can never change. Static you do use a dollar sign, the value can change. So that's really all for this tutorial. I hope you found this educational and entertaining. I know this can be a bit of a confusing one, so I kind of recommend you watch it over again if you really didn't grasp that concept, but all you really need to know is that constant static live outside of the class. Not really true, but think of it that way. They can exist without an instance of the class actually existing yet. That's it.