PHP OOPLesson 49Free preview
PHP Constants
This lesson is part of PHP · All levels
Summary
A constant is a fixed value that is defined once and cannot be changed during the run of a script. PHP provides the define() function to create global constants and the const keyword for both class and file contexts. A constant is suitable for configurations such as a basic URL, application mode, or fixed numeric values.
Key points
- The constant is not initiated by the $ sign and its value cannot be changed once it is created.
- Define() is a function, whereas const is a language constructor that should be at file/class level.
- Got a third parameter to make names less sensitive to capital letters.
- The constant value is taken by writing its name directly or via the function constant().
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.