diff --git a/Singleton/Singleton.php b/Singleton/Singleton.php index ee896e4..c728c31 100644 --- a/Singleton/Singleton.php +++ b/Singleton/Singleton.php @@ -16,6 +16,11 @@ namespace DesignPatterns; */ class Singleton { + /** + * @var cached reference to singleton instance + */ + protected static $instance; + /** * gets the instance via lazy initialization (created on first usage) * @@ -23,13 +28,12 @@ class Singleton */ public static function getInstance() { - static $instance; - - if (null === $instance) { - $instance = new self(); + + if (null === static::$instance) { + static::$instance = new static; } - return $instance; + return static::$instance; } /**