3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { protected static ?Foo $instance = null; public static function __callStatic($method, $args) { $instance = self::$instance ?? self::$instance = new static(); return $instance->__call($method, $args); } public function __call($method, $args) { if (method_exists($this, $method)) { return $instance->$method(...$args); } return $this; } protected function bar() { echo __METHOD__ . '<br />'; return $this; } protected function baz() { echo __METHOD__ . '<br />'; return $this; } } Foo::bar()->baz(); (new Foo())->bar()->baz();
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Undefined variable $instance in /in/moH0s on line 16 Fatal error: Uncaught Error: Call to a member function bar() on null in /in/moH0s:16 Stack trace: #0 /in/moH0s(10): Foo->__call('bar', Array) #1 /in/moH0s(37): Foo::__callStatic('bar', Array) #2 {main} thrown in /in/moH0s on line 16
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:
50.49 ms | 406 KiB | 5 Q