Skip to content

Instantly share code, notes, and snippets.

@levani
Last active November 19, 2015 14:14
Show Gist options
  • Save levani/565c1b913172bc686925 to your computer and use it in GitHub Desktop.
Save levani/565c1b913172bc686925 to your computer and use it in GitHub Desktop.
<?php
class SingletonClass {
private static $instance;
private function __construct() { }
public function __clone() {
trigger_error('Clone is not allowed.', E_USER_ERROR);
}
public static function init() {
if (!isset(self::$instance)) {
$c = __CLASS__;
self::$instance = new $c;
}
return self::$instance;
}
// other public, dynamic methods for singleton
}
$singleton = SingletonClass::init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment