3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Singleton{ private static $instance; private function __construct(){} public static function instance() { if (is_null(self::$instance)){ self::$instance = new static; } return self::$instance; } } $obj1 = Singleton::instance(); $obj2 = Singleton::instance(); var_dump(spl_object_hash($obj1), spl_object_hash($obj2)); $closure = function(){ return clone $this->instance; } $cloner = $closure->bindTo($obj1, 'private'); $obj3 = $cloner(); var_dump(spl_object_hash($obj3);
Output for 5.4.0 - 5.4.30
Parse error: syntax error, unexpected '$cloner' (T_VARIABLE) in /in/6qvG8 on line 42
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_VARIABLE in /in/6qvG8 on line 42
Process exited with code 255.