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 function(){ var_dump($this); return clone $this; }; }; $obj3 = null; $obj3 = $cloner->bindTo($obj1, 'Singleton')->__invoke(); var_dump($obj1, $obj3);
Output for git.master, git.master_jit, rfc.property-hooks
Warning: The magic method Singleton::__sleep() must have public visibility in /in/abSIe on line 7 Warning: The magic method Singleton::__wakeup() must have public visibility in /in/abSIe on line 8 bool(true) object(Singleton)#1 (0) { } object(Closure)#4 (1) { ["this"]=> object(Singleton)#1 (0) { } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
37.31 ms | 402 KiB | 8 Q