Created
June 9, 2014 04:11
-
-
Save dukeofgaming/8361b752a782826fdb8c to your computer and use it in GitHub Desktop.
Inheritable PHP 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
<?php | |
class Object{ | |
//... | |
private static $singletons = array(); | |
public static function &singleton(){ | |
$class = get_called_class(); | |
if(!array_key_exists($class, self::$singletons)){ | |
self::$singletons[$class] = new $class(); | |
} | |
return self::$singletons[$class]; | |
} | |
//... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment