Skip to content

Instantly share code, notes, and snippets.

@skamenetskiy
Last active December 15, 2015 04:29
Show Gist options
  • Save skamenetskiy/5202393 to your computer and use it in GitHub Desktop.
Save skamenetskiy/5202393 to your computer and use it in GitHub Desktop.
PHP Singleton sample
<?php
class Singleton
{
/** @var Singleton $_instance */
private static $_instance = null;
/**
* Returns a single instance of Singleton
*
* @returns Singleton
*/
public static function getIntance()
{
if(is_null(self::$_instance)){
self::$_instance = new self;
}
return self::$_instance;
}
/** Locking for singleton */
private __construct(){}
private __clone(){}
private __wakeup(){}
/**
* Just a test function
*/
public function test(){
echo 'Hello world!';
}
}
Singleton::getInstance()->test();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment