Advertisement
sebbu

b.src.php

Jul 15th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.66 KB | None | 0 0
  1. <?php
  2. namespace perso {
  3.     class A
  4.     {
  5.         private $a;
  6.         private static $b;
  7.         public function __construct()
  8.         {
  9.             //$this->a=new \A();
  10.             $class='\A';
  11.             $args=func_get_args();
  12.             if(version_compare(phpversion(), '5.6.0', '>=')){
  13.                 $instance = new $class(...$args);
  14.             }
  15.             else {
  16.                 $reflect  = new ReflectionClass($class);
  17.                 $instance = $reflect->newInstanceArgs($args);
  18.             }
  19.             $this->a=$instance;
  20.             self::$b=get_class($this->a);
  21.         }
  22.         public function __get(string $name)
  23.         {
  24.             $res=null;
  25.             if($name=='v')
  26.             {
  27.                 var_dump('v pre');
  28.             }
  29.             if(property_exists($this->a, $name))
  30.             {
  31.                 $res=$this->a->$name;
  32.             }
  33.             else $res=null;
  34.             if($name=='v')
  35.             {
  36.                 var_dump('v post');
  37.             }
  38.             return $res;
  39.         }
  40.         public function __set(string $name, $value)
  41.         {
  42.             if(property_exists($this->a, $name))
  43.             {
  44.                 $this->a->$name=$value;
  45.             }
  46.             return $this;
  47.         }
  48.         public function __call(string $name, array $arguments)
  49.         {
  50.             $res=null;
  51.             if($name=='m') var_dump('m pre');
  52.             if(method_exists($this->a, $name))
  53.             {
  54.                 $res=call_user_func_array(array($this->a, $name), $arguments);
  55.             }
  56.             if($name=='m') var_dump('m post');
  57.             return $res;
  58.         }
  59.         public static function __callStatic(string $name, array $arguments)
  60.         {
  61.             $res=null;
  62.             if($name=='q') var_dump('q pre');
  63.             if(method_exists(self::$b, $name))
  64.             {
  65.                 $res=call_user_func_array(array(self::$b, $name), $arguments);
  66.             }
  67.             if($name=='q') var_dump('q post');
  68.             return $res;
  69.         }
  70.         //cheating by exception handling
  71.         public static function __getStatic(string $name)
  72.         {
  73.             $res=null;
  74.             $class=(new \ReflectionClass(__CLASS__))->getShortName();
  75.             if(property_exists($class, $name))
  76.             {
  77.                 $res=$class::$$name;
  78.             }
  79.             return $res;
  80.         }
  81.         public static function __setStatic(string $name, $value)
  82.         {
  83.             $class=(new \ReflectionClass(__CLASS__))->getShortName();
  84.             if(property_exists($class, $name))
  85.             {
  86.                 $class::$$name=$value;
  87.             }
  88.             return $class;
  89.         }
  90.     };
  91. }
  92. namespace {
  93.     function is_empty($str)
  94.     {
  95.         return !empty($str);
  96.     }
  97.     function fix_error(Throwable $ex)
  98.     {
  99.         //var_dump($ex);
  100.         $str=$ex->getMessage();
  101.         if(strpos($str, 'Access to undeclared static property: ')!==0) return false;
  102.         $str=explode(':', $str);
  103.         array_shift($str);
  104.         $str=array_map('trim', $str);
  105.         $str=array_filter($str, 'is_empty');
  106.         if(strpos($str[0],'perso\\')===0) $class=substr($str[0], 6);
  107.         else $class=$str[0];
  108.         $prop=substr($str[2], 1);
  109.         //var_dump($class::$$prop);
  110.         //var_dump(call_user_func(array($str[0], '__getStatic'), $prop));
  111.         var_dump(call_user_func(array($str[0], '__getStatic'), $prop));
  112.         //var_dump('hello world');
  113.         return true;
  114.     }
  115. }
  116. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement