Skip to content

Instantly share code, notes, and snippets.

@michaelperrin
Created October 11, 2012 14:57
Show Gist options
  • Save michaelperrin/3872965 to your computer and use it in GitHub Desktop.
Save michaelperrin/3872965 to your computer and use it in GitHub Desktop.
Singleton class
<?php
class MyObject
{
protected static $instance;
protected function __construct() { }
/**
* Returns an instance of this class
* (this class uses the singleton pattern)
*
* @return MyObject
*/
public static function getInstance()
{
if (!isset(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment