O'Reilly logo

Core PHP Programming, Third Edition by Leon Atkinson

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

2.4. Constants

Constants are similar to variables, but they may be set only once. Some of them are created automatically by PHP; others you will create with the define function discussed in Chapter 11. You do not use the dollar-sign operator to get the value of a constant, and you may never use a constant on the left side of an assignment operator.

Although it is not necessary, it is customary to name constants exclusively with capital letters. This helps make them stand out in your script, as in Listing 2.8. PHP creates many constants upon startup, as described in Chapter 8.

Listing 2.8. Using a constant
<?php
    define("STANDARD_GREETING", "Hello, World!");
    print(STANDARD_GREETING);
?>

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