OOP: Class Constants
It is recommended to read about Constants first before reading about Class Constants.
Class constants are the same as regular Constants except they are decliared within a class. Once they are decared they are accesable from all scopes of the script. Class constants simular to Constants can only contain scalar values.
Class Constants have some advantages over constants is that when declared within a class it is much cleaner code and are significantly faster than constants declared with defne().
PHP Class Constant “Hello World” Example:
class foo { const BAR = "Hello World"; } echo foo::BAR;
Constants in General:
Constants differ from normal variables in that you don’t use the $ symbol to declare or use them.
Must be a constant expression (not a variable, a class member, mathematical operation or a function call).
No Comments »
RSS feed for comments on this post. TrackBack URL











