© Mikael Olsson 2016

Mikael Olsson, PHP 7 Quick Scripting Reference, 10.1007/978-1-4842-1922-5_13

13. Constants

Mikael Olsson

(1)Hammarland, Finland

A constantis a variable with a value that cannot be changed by the script. Therefore, such a value must be assigned at the same time that 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 because 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 ...

Get PHP 7 Quick Scripting Reference, Second Edition 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.