Created
January 10, 2018 19:09
-
-
Save maxviewup/3495243e7855bd237a22debbd405cd3a to your computer and use it in GitHub Desktop.
PHP Singleton Class
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
// simple singleton instance getter - one line | |
Class Foo { | |
private static $instance = null; | |
public static function get_instance() { | |
return self::$instance ?: self::$instance = new self; | |
} | |
// ...class code | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment