Skip to content

Instantly share code, notes, and snippets.

@egulhan
Created November 21, 2013 19:50
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 egulhan/7588358 to your computer and use it in GitHub Desktop.
Save egulhan/7588358 to your computer and use it in GitHub Desktop.
Getting instance of an class via static function.
<?php
class SampleClass
{
static private $instance;
/**
* This implements the 'singleton' design pattern
*/
static function getInstance()
{
if (!self::$instance) {
self::$instance = new SampleClass();
}
return self::$instance;
}
/**
* Private constructor
*/
private function __construct()
{
/* ... */
}
/* ... */
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment