Skip to content

Commit

Permalink
Merge pull request codeguy#504 from bocharsky-bw/patch-2
Browse files Browse the repository at this point in the history
Use static property instead of static variable
  • Loading branch information
philsturgeon committed Jun 12, 2015
2 parents f28550f + 17432d8 commit 85ce981
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions pages/Design-Patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
/**
Expand Down

0 comments on commit 85ce981

Please sign in to comment.