3v4l.org

run code in 300+ PHP versions simultaneously
<?php // explicit mention of methods that should be fluent // would be preferable to returning $this on null // since a method may very well return null as something // that is expected. interface Something { public function bar(); public function baz(); public function bat(); } interface SomethingFluent extends Something { public function bar(); public function baz(); public function bat(); } class Foo implements Something { public function bar() { var_dump(__METHOD__); } public function baz() { var_dump(__METHOD__); } public function bat() { var_dump(__METHOD__); return 'bat!'; } } class FluentWrapper { private $instance; private $fluentMethods; public function __construct($instance, array $fluentMethods = array()) { $this->instance = $instance; $this->fluentMethods = $fluentMethods; } public function __call($name, $args) { $result = call_user_func(array($this->instance, $name), $args); return in_array($name, $this->fluentMethods) ? $this : $result; } } class FluentFoo extends FluentWrapper implements SomethingFluent { public function __construct(Foo $foo) { parent::__construct($foo, array('bar', 'baz')); } } $foo = new FluentFoo(new Foo()); $bat = $foo ->bar() ->baz() ->bar() ->baz() ->bat(); print $bat."\n";
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Class FluentFoo contains 3 abstract methods and must therefore be declared abstract or implement the remaining methods (SomethingFluent::bar, SomethingFluent::baz, SomethingFluent::bat) in /in/8t3q1 on line 58
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:
54.93 ms | 401 KiB | 8 Q