Created
November 22, 2017 06:34
-
-
Save lastday154/ecc68d3c0fbe3ba2166f26c4d40f5d6c to your computer and use it in GitHub Desktop.
Singleton PHP
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 UserFactory | |
| { | |
| private function __construct() | |
| { | |
| } | |
| public static function Instance() | |
| { | |
| static $user = null; | |
| if ($user === null) { | |
| $user = new UserFactory(); | |
| } | |
| return $user; | |
| } | |
| } | |
| $fact = UserFactory::Instance(); | |
| $fact2 = UserFactory::Instance(); | |
| var_dump($fact== $fact2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment