3v4l.org

run code in 300+ PHP versions simultaneously
<?php foreach(new class( new Handler(15, \FizzBuzz::class, new Handler(3, \Fizz::class, new Handler(5, \Buzz::class, fn($n) => (string)$n, ))), range(1, 100)) implements IteratorAggregate{ function __construct(private $handler, private $input){} function getIterator(): Generator { return (function() { foreach($this->input as $n) yield ($this->handler)($n) ?><?php })()?><?php } } as $fizzbuzz) echo $fizzbuzz,PHP_EOL?><?php final class Handler{ function __construct(private $n, private $s, private $succ){} function isMatched(int $n):bool{return$n%$this->n===0?><?php} function __invoke(int $n){return $this->isMatched($n) ? $this : ($this->succ)($n)?><?php } function __toString(){ return $this->s?><?php }}
Output for 8.0.0
Fatal error: Uncaught Error: Class "Handler" not found in /in/SLqeg:2 Stack trace: #0 {main} thrown in /in/SLqeg on line 2
Process exited with code 255.
Output for 7.4.0 - 7.4.13
Parse error: syntax error, unexpected 'private' (T_PRIVATE), expecting variable (T_VARIABLE) in /in/SLqeg on line 7
Process exited with code 255.
Output for 7.3.0 - 7.3.25
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ')' in /in/SLqeg on line 5
Process exited with code 255.

preferences:
173.08 ms | 1395 KiB | 48 Q