Created
October 11, 2012 14:57
-
-
Save michaelperrin/3872965 to your computer and use it in GitHub Desktop.
Singleton class
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 | |
class MyObject | |
{ | |
protected static $instance; | |
protected function __construct() { } | |
/** | |
* Returns an instance of this class | |
* (this class uses the singleton pattern) | |
* | |
* @return MyObject | |
*/ | |
public static function getInstance() | |
{ | |
if (!isset(self::$instance)) { | |
self::$instance = new self(); | |
} | |
return self::$instance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment