|
Class Constants
It is possible to define constants
on a per-class basis remaining the same and unchangeable.
The default visibility of class constants is
It's also possible for interfaces to have constants. Look at the interface documentation for examples.
It's possible to reference the class using a variable.
The variable's value can not be a keyword (e.g. Note that class constants are allocated once per class, and not for each class instance. Example #1 Defining and using a constant
The special Example #2 Namespaced ::class example
Example #3 Class constant expression example
Example #4 Class constant visibility modifiers, as of PHP 7.1.0
Output of the above example in PHP 7.1: bar Fatal error: Uncaught Error: Cannot access private const Foo::BAZ in …
|