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 function __wakeup() { throw new Exception("Cannot unserialize singleton"); } 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(); // $thirdInstance = clone $oneInstance; var_dump($secondInstance); var_dump(new ReflectionClass($secondInstance)->getMethods());
Output for 5.4.0 - 5.4.25
Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in /in/mnbYM on line 37
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/mnbYM on line 25
Process exited with code 255.

preferences:
194.64 ms | 1395 KiB | 62 Q