Created
February 10, 2013 01:16
-
-
Save bayi/4747873 to your computer and use it in GitHub Desktop.
Singleton Trait for PHP
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 | |
trait SingletonClass { | |
protected static $instance; | |
final public static function getInstance() { | |
return isset(static::$instance) | |
? static::$instance | |
: static::$instance = new static; | |
} | |
final private function __construct() { | |
$this->__init(); | |
} | |
protected abstract function __init(); | |
final private function __wakeup() {} | |
final private function __clone() {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment