mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-12 19:06:24 +02:00
move Singleton::$_instance into Singleton::getInstance() method
This commit is contained in:
@ -16,11 +16,6 @@ namespace DesignPatterns;
|
|||||||
*/
|
*/
|
||||||
class Singleton
|
class Singleton
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \DesignPatterns\Singleton
|
|
||||||
*/
|
|
||||||
private static $_instance;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets the instance via lazy initialization (created on first usage)
|
* gets the instance via lazy initialization (created on first usage)
|
||||||
*
|
*
|
||||||
@ -28,11 +23,13 @@ class Singleton
|
|||||||
*/
|
*/
|
||||||
public static function getInstance()
|
public static function getInstance()
|
||||||
{
|
{
|
||||||
if (null === self::$_instance) {
|
static $instance;
|
||||||
self::$_instance = new self();
|
|
||||||
|
if (null === $instance) {
|
||||||
|
$instance = new self();
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$_instance;
|
return $instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user