3v4l.org

run code in 300+ PHP versions simultaneously
<?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; } private __invoke() {} } $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);
Output for 5.4.0 - 5.4.25
Parse error: syntax error, unexpected '__invoke' (T_STRING), expecting variable (T_VARIABLE) in /in/D5NFs on line 18
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in /in/D5NFs on line 18
Process exited with code 255.

preferences:
180.03 ms | 1395 KiB | 62 Q