mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-11 08:13:58 +02:00
Merge pull request #504 from bocharsky-bw/patch-2
Use static property instead of static variable
This commit is contained in:
@@ -72,21 +72,23 @@ one instance of a particular class. The singleton pattern enables us to do this.
|
|||||||
<?php
|
<?php
|
||||||
class Singleton
|
class Singleton
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var Singleton The reference to *Singleton* instance of this class
|
||||||
|
*/
|
||||||
|
private static $instance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the *Singleton* instance of this class.
|
* Returns the *Singleton* instance of this class.
|
||||||
*
|
*
|
||||||
* @staticvar Singleton $instance The *Singleton* instances of this class.
|
|
||||||
*
|
|
||||||
* @return Singleton The *Singleton* instance.
|
* @return Singleton The *Singleton* instance.
|
||||||
*/
|
*/
|
||||||
public static function getInstance()
|
public static function getInstance()
|
||||||
{
|
{
|
||||||
static $instance = null;
|
if (null === static::$instance) {
|
||||||
if (null === $instance) {
|
static::$instance = new static();
|
||||||
$instance = new static();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $instance;
|
return static::$instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user