@@ -4,19 +4,19 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Example |
| 6 | 6 | { |
| 7 | - use \ByJG\DesignPattern\Singleton; |
|
| 7 | + use \ByJG\DesignPattern\Singleton; |
|
| 8 | 8 | |
| 9 | - protected $_uniqId; |
|
| 9 | + protected $_uniqId; |
|
| 10 | 10 | |
| 11 | - protected function __construct() |
|
| 12 | - { |
|
| 13 | - $this->_uniqId = rand(0, 1000); |
|
| 14 | - } |
|
| 11 | + protected function __construct() |
|
| 12 | + { |
|
| 13 | + $this->_uniqId = rand(0, 1000); |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - public function getId() |
|
| 17 | - { |
|
| 18 | - return $this->_uniqId; |
|
| 19 | - } |
|
| 16 | + public function getId() |
|
| 17 | + { |
|
| 18 | + return $this->_uniqId; |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | 21 | } |
| 22 | 22 | |
@@ -24,10 +24,10 @@ |
||
| 24 | 24 | // This works; |
| 25 | 25 | // Must return the same ID; |
| 26 | 26 | $example1 = Example::getInstance(); |
| 27 | -echo $example1->getId() . "\n"; |
|
| 27 | +echo $example1->getId()."\n"; |
|
| 28 | 28 | |
| 29 | 29 | $example2 = Example::getInstance(); |
| 30 | -echo $example2->getId() . "\n"; |
|
| 30 | +echo $example2->getId()."\n"; |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | // That cannot work! |
@@ -15,17 +15,17 @@ |
||
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | - * @return static |
|
| 19 | - */ |
|
| 18 | + * @return static |
|
| 19 | + */ |
|
| 20 | 20 | public static function getInstance() |
| 21 | 21 | { |
| 22 | - static $instances; |
|
| 22 | + static $instances; |
|
| 23 | 23 | |
| 24 | - $calledClass = get_called_class(); |
|
| 24 | + $calledClass = get_called_class(); |
|
| 25 | 25 | |
| 26 | 26 | if (!isset($instances[$calledClass])) |
| 27 | 27 | { |
| 28 | - $instances[$calledClass] = new $calledClass(); |
|
| 28 | + $instances[$calledClass] = new $calledClass(); |
|
| 29 | 29 | } |
| 30 | 30 | return $instances[$calledClass]; |
| 31 | 31 | } |