O'Reilly logo

PHP Advanced for the World Wide Web: Visual QuickPro Guide by Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Constants

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"); 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required