Advertisement
sebbu

test __debugInfo() bis

Mar 30th, 2018
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.53 KB | None | 0 0
  1. <?php
  2. //header('Content-Type: text/plain');
  3. //var_dump(ReflectionProperty::IS_PUBLIC, ReflectionProperty::IS_PROTECTED, ReflectionProperty::IS_PRIVATE, ReflectionProperty::IS_STATIC);
  4. class Debug {
  5.     public function __debugInfo()
  6.     {
  7.         $rc = new ReflectionObject($this);
  8.         $class = $rc->getName();
  9.         $props = $rc->getProperties();
  10.         $props = array_filter($props, function($elem) use($class) { return ($elem->getDeclaringClass()->getName()==$class); });
  11.         $rc2=$rc;
  12.         while($rc2=$rc2->getParentClass())
  13.         {
  14.             $__class = $rc2->getName();
  15.             $props2 = $rc2->getProperties();
  16.             $props2 = array_filter($props2, function($elem) use($__class) { return ($elem->getDeclaringClass()->getName()==$__class); });
  17.             $props = array_merge($props, $props2);
  18.         }
  19.         $ar = array();
  20.         $props2=array();
  21.         foreach($props as $prop)
  22.         {
  23.             if($prop->isStatic()) continue;//ignore
  24.             if(!$prop->isDefault()) { $props2[]=$prop; continue; }//next loop
  25.             $prefix = ($prop->isProtected()? "\0*\0" :($prop->isPrivate()?"\0". $prop->getDeclaringClass()->getName() ."\0":''));
  26.             if(!$prop->isPrivate() && (array_key_exists($prop->getName(),$ar) || array_key_exists("\0*\0".$prop->getName(),$ar))) continue; // ignore if key already exists, except private
  27.             $prop->setAccessible(true); $ar[ $prefix.$prop->getName() ] = $prop->getValue($this);
  28.         }
  29.         foreach($props2 as $prop)
  30.         {
  31.             $prefix=($prop->isProtected()?"\0*\0":($prop->isPrivate()?"\0".$class."\0":''));
  32.             $prop->setAccessible(true); $ar[ $prefix.$prop->getName() ] = $prop->getValue($this);
  33.         }
  34.         return $ar;
  35.     }
  36. };
  37.  
  38. // echo 'normal class'."\r\n";
  39. class MyTestClass1
  40. {
  41.     public $a = 1;
  42.     protected $b = 2;
  43.     private $c = 3;
  44.     public static $z = 1;
  45.     protected static $y = 2;
  46.     private static $x = 3;
  47. }
  48. $test1=new MyTestClass1();
  49. // var_dump($test1);
  50. // echo 'normal class with complete debugInfo'."\r\n";
  51. class MyTestClass3 extends Debug
  52. {
  53.     public $a = 1;
  54.     protected $b = 2;
  55.     private $c = 3;
  56.     public static $z = 1;
  57.     protected static $y = 2;
  58.     private static $x = 3;
  59. }
  60. $test3=new MyTestClass3();
  61. // var_dump($test3);
  62. // echo 'first herited class'."\r\n";
  63. class MyTestClass4 extends MyTestClass1
  64. {
  65.     public $d = 4;
  66.     protected $e = 5;
  67.     private $f = 6;
  68.     public static $w = 4;
  69.     protected static $v = 5;
  70.     private static $u = 6;
  71. }
  72. $test4 = new MyTestClass4();
  73. // var_dump($test4);
  74. // echo 'first herited class with complete debugInfo'."\r\n";
  75. class MyTestClass5 extends MyTestClass3
  76. {
  77.     public $d = 4;
  78.     protected $e = 5;
  79.     private $f = 6;
  80.     public static $w = 4;
  81.     protected static $v = 5;
  82.     private static $u = 6;
  83. }
  84. $test5 = new MyTestClass5();
  85. // var_dump($test5);
  86. echo 'second herited class'."\r\n";
  87. class MyTestClass6 extends MyTestClass4
  88. {
  89.     public $g = 7;
  90.     protected $h = 8;
  91.     private $i = 9;
  92.     public static $t = 7;
  93.     protected static $s = 8;
  94.     private static $r = 9;
  95. }
  96. $test6 = new MyTestClass6();
  97. var_dump($test6);
  98. echo 'second herited class with complete debugInfo'."\r\n";
  99. class MyTestClass7 extends MyTestClass5
  100. {
  101.     public $g = 7;
  102.     protected $h = 8;
  103.     private $i = 9;
  104.     public static $t = 7;
  105.     protected static $s = 8;
  106.     private static $r = 9;
  107. }
  108. $test7 = new MyTestClass7();
  109. var_dump($test7);//*/
  110. echo 'class using second inherited class'."\r\n";
  111. class MyTestClassBis_1
  112. {
  113.     public $a = NULL;
  114.     protected $b = NULL;
  115.     private $c = NULL;
  116.     public function __construct()
  117.     {
  118.         global $test7,$test6;
  119.         $this->a = $test7;
  120.         $this->b = $test6;
  121.         $this->c = $test7;
  122.         $this->{1} = "un";
  123.         self::$x = $test7;
  124.         self::$y = $test7;
  125.         self::$z = $test7;
  126.     }
  127.     static public $z = NULL;
  128.     static protected $y = NULL;
  129.     static private $x = NULL;
  130. };
  131. $test8 = new MyTestClassBis_1();
  132. var_dump($test8);
  133. echo 'class using second inherited class, with complete debugInfo'."\r\n";
  134. class MyTestClassBis_1b extends Debug
  135. {
  136.     public $a = NULL;
  137.     protected $b = NULL;
  138.     private $c = NULL;
  139.     public function __construct()
  140.     {
  141.         global $test7,$test6;
  142.         $this->a = $test7;
  143.         $this->b = $test6;
  144.         $this->c = $test7;
  145.         $this->{1} = "un";
  146.         self::$x = $test7;
  147.         self::$y = $test7;
  148.         self::$z = $test7;
  149.     }
  150.     static public $z = NULL;
  151.     static protected $y = NULL;
  152.     static private $x = NULL;
  153. };
  154. $test8b = new MyTestClassBis_1b();
  155. var_dump($test8b);
  156. echo 'second class using second inherited class'."\r\n";
  157. class MyTestClassBis_2 extends MyTestClassBis_1
  158. {
  159.    
  160. };
  161. $test9 = new MyTestClassBis_2();
  162. var_dump($test9);
  163. echo 'second class using second inherited class, with complete debugInfo'."\r\n";
  164. class MyTestClassBis_2b extends MyTestClassBis_1b
  165. {
  166.    
  167. };
  168. $test9b = new MyTestClassBis_2b();
  169. var_dump($test9b);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement