mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-11 00:03: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
|
||||
class Singleton
|
||||
{
|
||||
/**
|
||||
* @var Singleton The reference to *Singleton* instance of this class
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Returns the *Singleton* instance of this class.
|
||||
*
|
||||
* @staticvar Singleton $instance The *Singleton* instances of this class.
|
||||
*
|
||||
* @return Singleton The *Singleton* instance.
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
static $instance = null;
|
||||
if (null === $instance) {
|
||||
$instance = new static();
|
||||
if (null === static::$instance) {
|
||||
static::$instance = new static();
|
||||
}
|
||||
|
||||
return $instance;
|
||||
|
||||
return static::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user