Created
May 24, 2014 03:25
-
-
Save shadda/39e34f7c8594fe3b52de 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 | |
| trait Singleton | |
| { | |
| private static $_instance; | |
| public static function getInstance() | |
| { | |
| if(!(self::$_instance instanceof self)) | |
| { | |
| self::$_instance = new self; | |
| } | |
| return self::$_instance; | |
| } | |
| } | |
| //and in another class | |
| class SomeShit | |
| { | |
| use Singleton; | |
| } | |
| $singleton = SomeShit::getInstance(); | |
| $singleton->foo = 'bar'; | |
| var_dump($singleton); | |
| $singleton = SomeShit::getInstance(); | |
| var_dump($singleton); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment