3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Singleton { private static $instance = null; final private function __construct() {} final private function __clone() {}jkjl 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);
Output for 5.4.0 - 5.4.25
Parse error: syntax error, unexpected 'jkjl' (T_STRING), expecting function (T_FUNCTION) in /in/02L29 on line 8
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in /in/02L29 on line 8
Process exited with code 255.

preferences:
186.17 ms | 1395 KiB | 62 Q