From the course: PHP: Object-Oriented Programming
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Class constants - PHP Tutorial
From the course: PHP: Object-Oriented Programming
Class constants
- [Instructor] In this movie, we're going to learn about class constants. You've probably been using constants before in PHP. They're used for values which don't change. Well, class constants are just for class values, which don't change. The way that we define them in our class is we use the keyword const, C-O-N-S-T, followed by the name in all capital letters, just like we do with normal constants. The value that we set a constant to can be something simple like a string or a number or an array or it can contain mathematical expressions. If you're using a new version of PHP, that is something later than 7.1, then you also can put a visibility modifier in front of that const keyword in order to make something public, protected or private. Prior to 7.1, and by default, it's going to be set to public. So constants are available publicly outside the class as well as inside the class. The way that you reference those…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.