December 2001
Intermediate to advanced
520 pages
13h 42m
English
Constants are a special type of variable that don't get enough attention, in my humble opinion. Constants, as the name would imply, contain a value that does not, nor cannot, change during the course of a script. Furthermore, constants have the added advantage of being global in scope, meaning they are accessible within your functions automatically.
Constants are case-sensitive, as are all variables in PHP. As a rule, constants are always written in all uppercase letters. When naming constants, use the same rules as you do variables—a letter or underscore followed by letters, numbers, or underscores—but omit the initial dollar sign.
A constant is created by using the define() function, like so:
define ("CONSTANT_NAME", "value");
Read now
Unlock full access