3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Singleton { private function __construct(){} private function __clone(){} private function __sleep(){} private function __wakeup(){} private static $instance; public static function getInstance() { if ( ! self::$instance) { self::$instance = new static(); } return self::$instance; } } $obj1 = Singleton::getInstance(); $obj2 = Singleton::getInstance(); var_dump(spl_object_hash($obj1) == spl_object_hash($obj2)); $cloner = function(){ return new Closure(); } $obj3 = null; $obj3 = $cloner::bindTo($obj1)->__invoke(); var_dump(spl_object_hash($obj1) == spl_object_hash($obj3));
Output for 5.4.0 - 5.4.26
Parse error: syntax error, unexpected '$obj3' (T_VARIABLE) in /in/jMXKu on line 37
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_VARIABLE in /in/jMXKu on line 37
Process exited with code 255.

preferences:
192.49 ms | 1394 KiB | 63 Q