3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait Singleton { private static $instance; private function __construct() {} private function __clone() {} private function __wakeup() {} public function getInstance() { if (empty(static::$instanse)) { return new static(); } else { return static::$instance; } } } class Foo { use Singleton; private $bar = 2; public function incBar() { $this->bar++; } public function getBar() { return $this->bar."<br/>"; } } $foo = Foo::getInstance(); echo $foo->getBar(); $foo->incBar(); echo $foo->getBar();
Output for git.master, git.master_jit, rfc.property-hooks
Warning: The magic method Singleton::__wakeup() must have public visibility in /in/AJmhE on line 9 Fatal error: Uncaught Error: Non-static method Foo::getInstance() cannot be called statically in /in/AJmhE:38 Stack trace: #0 {main} thrown in /in/AJmhE on line 38
Process exited with code 255.

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:
112.66 ms | 401 KiB | 8 Q