Skip to content

Instantly share code, notes, and snippets.

@thefuxia
Created October 8, 2009 14:08
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 thefuxia/205045 to your computer and use it in GitHub Desktop.
Save thefuxia/205045 to your computer and use it in GitHub Desktop.
Template for a singleton.
<?php
/**
* Description
*
* Aufruf nur durch
<code>{NAME}::getInstance()</code>
* @author Thomas Scholz <info@toscho.de>
*/
class {NAME} {
/**
* @static $instance Objekt
* @access private;
*/
private static $instance = NULL;
private function __construct()
{
// Tu was
}
/**
* Verhindert das Klonen des Objektes.
*/
private final function __clone() {}
public static function getInstance()
{
if ( self::$instance === NULL )
{
$class = get_class();
self::$instance = new $class;
}
return self::$instance;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment