3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Container extends ArrayObject { function __set($k,$c){$this[$k]=$c;} function __get($k){return $this->get($k);} function get(string $id){return $this[$id]($this);} function has(string $id): bool {return isset($this[$id]);} } class Fizz { public function __toString() { return 'Fizz'; } } class Buzz { public function __toString() { return 'Buzz'; } } class FizzBuzz { public function __construct( private Fizz $fizz, private Buzz $buzz ) {} public function __invoke(int $i): string { if (!($i % 15)) return $this->fizz . $this->buzz; if (!($i % 3)) return (string) $this->fizz; if (!($i % 5)) return (string) $this->buzz; return (string) $i; } } $c = new Container; $c->fizz = fn () => new Fizz; $c->buzz = fn () => new Buzz; $c->fizzBuzz = fn ($c) => new FizzBuzz($c->fizz, $c->buzz); foreach (range(1, 15) as $i) { echo $c->get('fizzBuzz')($i) . "\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz

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:
48.03 ms | 405 KiB | 5 Q