Skip to content

Instantly share code, notes, and snippets.

@dukeofgaming
Created June 9, 2014 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dukeofgaming/8361b752a782826fdb8c to your computer and use it in GitHub Desktop.
Save dukeofgaming/8361b752a782826fdb8c to your computer and use it in GitHub Desktop.
Inheritable PHP Singleton
<?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