O'Reilly logo

PHP Quick Scripting Reference by Mikael Olsson

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

CHAPTER 13

image

Constants

A constant is a variable with a value that cannot be changed in the script. Such a value must therefore be assigned at the same time as the constant is created. PHP provides two methods for creating constants: the const modifier and the define function.

Const

The const modifier is used to create class constants. Unlike regular properties, class constants do not have an access level specified, as they are always publicly visible. They also do not use the dollar sign parser token ($). The naming convention for constants is all-uppercase, with underscores separating each word.

class MyCircle{  const PI = 3.14;}

Constants must ...

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