Created
August 18, 2011 08:42
-
-
Save salathe/1153670 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
| string(7) "Example" | |
| object(Example)#1 (0) { | |
| } | |
| Fatal error: Call to private Example::__construct() from invalid context in <file> on line 18 |
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 function __construct() { | |
| var_dump(get_called_class()); | |
| } | |
| public static function getInstance() { | |
| return new static; | |
| } | |
| } | |
| class Example { | |
| use Singleton; | |
| } | |
| var_dump(Example::getInstance()); | |
| var_dump(new Example); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment