Using Class Constants in PHP5 : const « Class « PHP






Using Class Constants in PHP5

 
<?php
     class MyExample {
          private $myvar;
          public $readme;
          const MY_CONSTANT = 10;

          public function showConstant() {
               echo "The value is: ".MY_CONSTANT;
          }
     }
     $inst = new MyExample;
     $inst->showConstant();
     echo "The value: ".ConstExample::MY_CONSTANT;
?>
  
  








Related examples in the same category

1.Constant definition is considered a static member of the class
2.Counting the elements in an array
3.Finding the size of an array
4.Using Class Constants