Advertisement
fruffl

Get defined const?

Feb 25th, 2012
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1.  
  2.  
  3.        
  4.         final public function __construct($default = self::__default)
  5.         {
  6.             $this->__reflectionBase  = new ReflectionClass(__CLASS__);
  7.             //$this->__reflectionClass = new ReflectionClass($this->getQualifiedName());
  8.             $this->__reflectionClass = new ReflectionClass(get_class($this));
  9.             $this->__constantsBase   = $this->__reflectionBase->getConstants();
  10.             $this->__constantsClass  = $this->__reflectionClass->getConstants();
  11.            
  12.            
  13.             var_dump($this->__constantsBase);
  14.             var_dump($this->__constantsClass);
  15. /*
  16. array(5) {
  17.   ["__default"]=>
  18.   NULL
  19.   ["__STRICT_INTEGER"]=>
  20.   int(1)
  21.   ["__STRICT_STRING"]=>
  22.   int(2)
  23.   ["__STRICT_FLOAT"]=>
  24.   int(4)
  25.   ["__STRICT_SCALAR"]=>
  26.   int(7)
  27. }
  28. array(7) {
  29.   ["APPLE"]=>
  30.   int(1)
  31.   ["ORANGE"]=>
  32.   int(2)
  33.   ["__default"]=>
  34.   NULL
  35.   ["__STRICT_INTEGER"]=>
  36.   int(1)
  37.   ["__STRICT_STRING"]=>
  38.   int(2)
  39.   ["__STRICT_FLOAT"]=>
  40.   int(4)
  41.   ["__STRICT_SCALAR"]=>
  42.   int(7)
  43. }
  44. */
  45.            
  46.             // remove private constants from child
  47.             $diff = array_intersect_assoc($this->__constantsBase, $this->__constantsClass);        
  48.             foreach($diff as $const => $val)
  49.             {
  50.                 if($const == '__default')
  51.                     continue;
  52.                
  53.                 unset($this->__constantsClass[$const]);
  54.             }
  55.            
  56.             var_dump($this->__constantsBase);
  57.             var_dump($this->__constantsClass);
  58. /*
  59.  
  60. array(5) {
  61.   ["__default"]=>
  62.   NULL
  63.   ["__STRICT_INTEGER"]=>
  64.   int(1)
  65.   ["__STRICT_STRING"]=>
  66.   int(2)
  67.   ["__STRICT_FLOAT"]=>
  68.   int(4)
  69.   ["__STRICT_SCALAR"]=>
  70.   int(7)
  71. }
  72. array(3) {
  73.   ["APPLE"]=>
  74.   int(1)
  75.   ["ORANGE"]=>
  76.   int(2)
  77.   ["__default"]=>
  78.   NULL
  79. }
  80. */         
  81.            
  82.             die();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement