Created
April 1, 2017 18:01
-
-
Save nickrouty/bb13ac713746079c16ec45ff56e86e2b to your computer and use it in GitHub Desktop.
Example Singleton
This file contains 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
class ExampleSingleton { | |
private $properties = array(); | |
private static $instance; | |
private __construct(){} | |
public getInstance() | |
{ | |
if (empty(self::$instance)) { | |
self::$instance = new ExampleSingleton(); | |
} | |
return self::$instance; | |
} | |
public function setProperty($key, $value) | |
{ | |
$this->properties[$key] = $value; | |
} | |
public function getProperty($key) | |
{ | |
return $this->properties[$key]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment