- var_dump: documentation ( source)
<?php
class Singleton
{
private static $instance = null;
final private function __construct() {}
final private function __clone() {}
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);