Class constants are a bit different than normal(?) constants. Mostly they are used to declare some constant data inside a class.
You can define class constants inside a class with a const keyword and they’ll stay unchangeable. They can be redefined by the child class though.
Constant identifiers are case-sensitive but they are always defined in uppercase.
By default, the visibility of class constants if public.
You can have constants in interfaces too!
You can reference a class using a variable but the value of the variable can not be a keyword like self, static or parent.
Class constants are allocated once per class, and not for each class instance.
Class Constant Examples
You can use the scope resolution operator (::) to access the class constant. For e.g.
Class constants can be simple like this:
You can also define it inside a method:
showGreetings(); //Hello World! ?>
Class constant expression example
Class constants with visibility
From PHP 7.1.0, you can define class constants with visibility (access) modifiers.