SHOW:
|
|
- or go back to the newest paste.
| 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 | - | if(TRUE === array_key_exists($thread, self::$instances)) |
| 12 | + | |
| 13 | - | return self::$instances[$thread]; // break point |
| 13 | + | if(isset(self::$instances[$thread])) |
| 14 | return self::$instances[$thread]; | |
| 15 | - | self::$instances[$thread] = new self; |
| 15 | + | |
| 16 | - | return self::$instances[$thread]; |
| 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 | - | static::$counter++; |
| 23 | + | |
| 24 | */ | |
| 25 | - | if(static::$counter < 4) |
| 25 | + | |
| 26 | - | {
|
| 26 | + | |
| 27 | - | //var_dump(self::getInstance() instanceOf Foo); // trigger infinity... why? |
| 27 | + | |
| 28 | - | var_dump(self::getInstance()); // void (displays nothing) |
| 28 | + | |
| 29 | - | var_dump(self::$instances); // void (displays nothing) when calling self::getInstance() |
| 29 | + | |
| 30 | - | return; |
| 30 | + | |
| 31 | - | } |
| 31 | + | private function __staticconstruct() |
| 32 | {
| |
| 33 | - | var_dump(self::$instances); |
| 33 | + | var_dump(self::getInstance() instanceOf Foo); |
| 34 | - | var_dump(debug_backtrace(0, 4)); |
| 34 | + | return $this; |
| 35 | - | die(); |
| 35 | + | |
| 36 | } |