Class.php Constants
Jul 02, 2009
Author: Developer
Class constants work in the same way as regular constants, except they are scoped within a class. Class constants are public, and accessible from all scopes; for example, the following script will output Hello World:
class foo {
const BAR = "Hello World";
}
echo foo::BAR;
IMPORTANT:Note that class constants suffer from the same limitations as regular constants— therefore, they can only contain scalar values.
Class constants have several advantages over traditional constants: since they are encapsulated in a class, they make for much cleaner code, and they are significantly faster than those declared with the define() construct.
views 1983



