Advertisement
fruffl

infinity/registry

Aug 21st, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. <?PHP
  2.     NAMESPACE ILLI\Bug;
  3.     INTERFACE Foo {}
  4.     CLASS Instance IMPLEMENTS Foo
  5.     {
  6.         private static $instances = [];
  7.        
  8.         public static function getInstance()
  9.         {  
  10.             $thread = get_called_class();
  11.            
  12.             if(TRUE === array_key_exists($thread, self::$instances))
  13.                 return self::$instances[$thread];       // break point
  14.            
  15.             self::$instances[$thread] = new self;
  16.             return self::$instances[$thread];
  17.         }
  18.  
  19.         private static $counter = 0;
  20.        
  21.         private function __construct()
  22.         {
  23.             static::$counter++;
  24.            
  25.             if(static::$counter < 4)
  26.             {
  27.                 //var_dump(self::getInstance() instanceOf Foo); // trigger infinity... why?
  28.                 var_dump(self::getInstance());          // void (displays nothing)
  29.                 var_dump(self::$instances);         // void (displays nothing) when calling self::getInstance()
  30.                 return;
  31.             }
  32.            
  33.             var_dump(self::$instances);
  34.             var_dump(debug_backtrace(0, 4));
  35.             die();
  36.         }
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement