Advertisement
fruffl

solution

Aug 21st, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?PHP
  2.     NAMESPACE ILLI\Bug;
  3.     INTERFACE Foo {}
  4.  
  5.     CLASS Instance IMPLEMENTS Foo
  6.     {
  7.         private static $instances = [];
  8.        
  9.         public static function getInstance()
  10.         {  
  11.             $thread = get_called_class();
  12.            
  13.             if(isset(self::$instances[$thread]))
  14.                 return self::$instances[$thread];
  15.            
  16.             self::$instances[$thread] = new $thread;
  17.             return self::$instances[$thread]->__staticconstruct();
  18.         }
  19.         /*
  20.         use tInstance
  21.         {
  22.             tInstance_get as public getInstance;
  23.         }
  24.         */
  25.         private static $counter = 0;
  26.        
  27.         private function __construct()
  28.         {
  29.         }
  30.        
  31.         private function __staticconstruct()
  32.         {
  33.             var_dump(self::getInstance() instanceOf Foo);
  34.             return $this;
  35.         }
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement