3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Singleton { private static $instance = null; final private function __construct() {} final private function __clone() {} final private function __sleep() {} private function __invoke() {} public static function getInstance() { if (!self::$instance) { self::$instance = new self; } return self::$instance; } } $oneInstance = Singleton::getInstance(); echo "Cloneable outside:", var_dump((new ReflectionClass('Singleton'))->isCloneable()); $cloner = function () { return clone $this; }; $secondInstance = $cloner->bindTo($oneInstance, 'Singleton')->__invoke(); var_dump($oneInstance, $secondInstance);