PHP Class Constants:
Sometimes we need to have constant values in our
program which remains same through and through. We do not need to put a $ sign
before the constant to use or to declare it.
The value of the constant should remain unchanged
that means it must be a constant expression.
Example:
<?php
class A
{
const newValue="Constant value does not consist $ sign";
function display()
{
echo self::newValue."\n";
}
}
$a=new A();
$a->display();
?>
Output:
Constant
value does not consist $ sign Explanation:
In the above example there is a single class declaration named A. Outside of this class
No comments:
Post a Comment