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 ...

Get PHP Quick Scripting Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.