Advertisement
fruffl

Whats wrong?

Jan 17th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.06 KB | None | 0 0
  1. <?PHP
  2.     class fu
  3.     {
  4.         protected $__defaultConfig = [];
  5.         public function __construct()
  6.         {
  7.             $class = get_called_class();
  8.             $props = [];
  9.  
  10.             do
  11.             {
  12.                 foreach((new \ReflectionClass($class))->getDefaultProperties() as $property => $value) // <---
  13.                 {
  14.                     if(!in_array($property, ['__autoConfig', '__defaultConfig']))
  15.                         continue;
  16.                    
  17.                     var_dump([$class.'::'.$property => $value]);
  18.                 }
  19.             }
  20.             while($class = get_parent_class($class));
  21.  
  22.             /*
  23.             // same...
  24.             foreach($this->parents() as $class)
  25.             {
  26.                 foreach((new \ReflectionClass($class))->getDefaultProperties() as $property => $value)
  27.                 {
  28.                     if(!in_array($property, ['__autoConfig', '__defaultConfig']))
  29.                         continue;
  30.                    
  31.                     var_dump([$class.'::'.$property => $value]);
  32.                 }
  33.             }
  34.             */
  35.         }
  36.     }
  37.  
  38.     class baz extends fu
  39.     {
  40.         protected $__defaultConfig = [];
  41.     }
  42. ?>
  43.  
  44.  
  45. // actual
  46.  
  47. array(1) {
  48.   ["fu::__defaultConfig"]=>
  49.   array(7) {
  50.     ["scheme"]=>
  51.     string(4) "http"
  52.     ["query"]=>
  53.     NULL
  54.     ["fragment"]=>
  55.     NULL
  56.     ["protocol"]=>
  57.     NULL
  58.     ["auth"]=>
  59.     NULL
  60.     ["version"]=>
  61.     string(3) "1.1"
  62.     ["headers"]=>
  63.     array(0) {
  64.     }
  65.   }
  66. }
  67. array(1) {
  68.   ["baz::__defaultConfig"]=>
  69.   array(7) {
  70.     ["scheme"]=>
  71.     string(4) "http"
  72.     ["query"]=>
  73.     NULL
  74.     ["fragment"]=>
  75.     NULL
  76.     ["protocol"]=>
  77.     NULL
  78.     ["auth"]=>
  79.     NULL
  80.     ["version"]=>
  81.     string(3) "1.1"
  82.     ["headers"]=>
  83.     array(0) {
  84.     }
  85.   }
  86. }
  87.  
  88. // expected
  89.  
  90. array(1) {
  91.   ["fu::__defaultConfig"]=>
  92.   array(7) {
  93.     ["scheme"]=>
  94.     string(4) "http"
  95.     ["query"]=>
  96.     NULL
  97.     ["fragment"]=>
  98.     NULL
  99.     ["protocol"]=>
  100.     NULL
  101.     ["auth"]=>
  102.     NULL
  103.     ["version"]=>
  104.     string(3) "1.1"
  105.     ["headers"]=>
  106.     array(0) {
  107.     }
  108.   }
  109. }
  110. array(1) {
  111.   ["baz::__defaultConfig"]=>
  112.   array(7) {
  113.     ["scheme"]=>
  114.     string(4) "tcp"
  115.     ["host"]=>
  116.     string(9) "localhost"
  117.     ["port"]=>
  118.     NULL
  119.     ["username"]=>
  120.     NULL
  121.     ["password"]=>
  122.     NULL
  123.     ["path"]=>
  124.     NULL
  125.     ["body"]=>
  126.     array(0) {
  127.     }
  128.   }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement