The limitations of constants in PHP

chinmay.sahoo

New member
Class constants are fine as long as they’re willing to do our bidding, but their limitations tend to show up early. The value of a constant can be set only when it’s defined, and it cannot be defined inside methods in a class. You can only assign plain values to a constant; there is no way to assign an object to it. You can’t even use string concatenation when defining a constant.
 
It is possible to define constant values on a per-class basis remaining the same and unchangeable. Constants differ from normal variables in that you don't use the $ symbol to declare or use them.
The value must be a constant expression, not (for example) a variable, a property, or a function call.

Deliver2inbox
 
Back
Top