Skip to content

Instantly share code, notes, and snippets.

@LiamChapman
Created February 21, 2014 10:14
Show Gist options
  • Select an option

  • Save LiamChapman/9131888 to your computer and use it in GitHub Desktop.

Select an option

Save LiamChapman/9131888 to your computer and use it in GitHub Desktop.
Common Singleton pattern in php
<?php
abstract class Singleton {
protected function __construct() {}
final public static function instance () {
static $instances = array();
$calledClass = get_called_class();
if (!isset($instances[$calledClass])) {
$instances[$calledClass] = new $calledClass();
}
return $instances[$calledClass];
}
final private function __clone() {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment