SHARE
TWEET

Untitled

a guest Oct 12th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.   class MyClass {
  4.    
  5.     const CONST_VALUE = "A constant value";
  6.    
  7.   }
  8.  
  9.   $classname = 'MyClass';
  10.   echo $className::CONST_VALUE."<br>"; // Displays 'A constant value'
  11.   echo MyClass::CONST_VALUE."<br>"; // Displays 'A constant value'
  12.  
  13.   class OtherClass extends MyClass {
  14.    
  15.     // Becauase this property is static we can DIRECTLY access it
  16.     public static $my_static = 'Static property';
  17.    
  18.     public static function doubleColon() {
  19.      
  20.       echo parent::CONST_VALUE."<br>"; // Displays 'A constant value'
  21.       echo self::CONST_VALUE."<br>"; // Displays 'Static property'
  22.      
  23.     }
  24.    
  25.   }
  26.  
  27.   $classname = 'OtherClass';
  28.   echo $classname::doubleColon();
  29.   OtherClass::doubleColon();
  30.  
  31.  
  32. ?>
RAW Paste Data
Top