<?php
class ConstantExample
{
const CONSTANT = "value unchanged";
function constantInFunction() {
echo self::CONSTANT; // Constant variable is accessible inside function of Class
}
}
echo ConstantExample::CONSTANT; // Constant variable is accessible outside of Class
$classname = "ConstantExample";
echo $classname::CONSTANT; // As of PHP 5.3.0, Constant variable is accessible by Class variable
$classObj = new ConstantExample();
echo $classObj::CONSTANT."\n"; // As of PHP 5.3.0, Constant variable is accessible by Class object
?>