Skip to content

Instantly share code, notes, and snippets.

@maxviewup
Created January 10, 2018 19:09
Show Gist options
  • Save maxviewup/3495243e7855bd237a22debbd405cd3a to your computer and use it in GitHub Desktop.
Save maxviewup/3495243e7855bd237a22debbd405cd3a to your computer and use it in GitHub Desktop.
PHP Singleton Class
// 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