In this tutorial we will study how to declare a class constant in PHP. 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.
In this tutorial we will study how to declare a class constant in PHP. 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.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