Created
March 26, 2019 10:37
-
-
Save woprrr/acf25906404bda421ab0b9481bb2cadc to your computer and use it in GitHub Desktop.
A dummy/simple singleton to test it.
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 MySingleton. | |
*/ | |
class MySingleton | |
{ | |
private static $instance; | |
private function __construct() {} | |
/** | |
* @return \MySingleton | |
*/ | |
public static function getInstance() | |
{ | |
if (!self::$instance) { | |
self::$instance = new self(); | |
} | |
return self::$instance; | |
} | |
} | |
$singleton1 = MySingleton::getInstance(); | |
$singleton = MySingleton::getInstance(); | |
var_dump($singleton); | |
var_dump($singleton1); | |
var_dump($singleton1 === $singleton); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment