Home Tutorial Php Phpoop PHP Class Constant

 
 

Share on Google+Share on Google+
PHP Class Constant
Posted on: February 18, 2010 at 12:00 AM
Advertisement
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

Explanation:
In the above example there is a single class declaration named A. Outside of this class
Advertisement

Related Tags for PHP Class Constant:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 18, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com