Skip to content

Instantly share code, notes, and snippets.

@woprrr
Created March 26, 2019 10:37
Show Gist options
  • Save woprrr/acf25906404bda421ab0b9481bb2cadc to your computer and use it in GitHub Desktop.
Save woprrr/acf25906404bda421ab0b9481bb2cadc to your computer and use it in GitHub Desktop.
A dummy/simple singleton to test it.
<?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