Last active
December 15, 2015 04:29
-
-
Save skamenetskiy/5202393 to your computer and use it in GitHub Desktop.
PHP Singleton sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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