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. Likestatic members, constant values can not be accessed from an instance of the object.
Example 18-13. Defining and using a constant <?php classMyClass{ constconstant='constant value';
functionshowConstant() { echo self::constant."\n"; } }
echoMyClass::constant."\n";
$class= newMyClass(); $class->showConstant(); /* echo $class::constant; is not allowed */ ?>
|
|