mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-02-24 01:32:22 +01:00
Merge pull request #35 from olekhy/patch-1
use static class property instead of static variable for Singleton
This commit is contained in:
commit
3d8098c5e4
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user