Created
March 3, 2014 16:46
-
-
Save you-think-you-are-special/9329080 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
trait Singleton | |
{ | |
protected static $instance; | |
protected function __construct() | |
{ | |
static::setInstance($this); | |
} | |
final public static function setInstance($instance) | |
{ | |
static::$instance = $instance; | |
return static::$instance; | |
} | |
final public static function getInstance() | |
{ | |
return isset(static::$instance) | |
? static::$instance | |
: static::$instance = new static; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment