Last active
November 19, 2015 14:14
-
-
Save levani/565c1b913172bc686925 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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