Skip to content

Instantly share code, notes, and snippets.

@magussiro
Forked from jaceju/Singleton.php
Created July 17, 2020 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magussiro/c7f5453f56854765a94287fce7b067b9 to your computer and use it in GitHub Desktop.
Save magussiro/c7f5453f56854765a94287fce7b067b9 to your computer and use it in GitHub Desktop.
<?php
trait Singleton
{
protected static $_instance = null;
public static function getInstance()
{
if (static::$_instance === null
|| !(static::$_instance instanceof static)) {
static::$_instance = new static();
}
return static::$_instance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment