Merge pull request #35 from olekhy/patch-1

use static class property instead of static variable for Singleton
This commit is contained in:
Dominik Liebler
2013-09-21 15:10:07 -07:00

View File

@@ -19,6 +19,11 @@ namespace DesignPatterns\Singleton;
*/
class Singleton
{
/**
* @var cached reference to singleton instance
*/
protected static $instance;
/**
* gets the instance via lazy initialization (created on first usage)
*
@@ -26,13 +31,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;
}
/**