3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); set_time_limit(1); stream_wrapper_register('fizzbuzz', FizzBuzzStreamWrapper::class); require 'fizzbuzz://3'; final class FizzBuzzStreamWrapper { private int $counter = 1; private int $length = 15; /** @var resource */ public $context; public function stream_open(string $path, $mode, $options, &$opened_path): bool { echo 'called `' . __METHOD__ . '` with ' . json_encode(func_get_args()) . PHP_EOL; preg_match('#([\d]+$)#', $path, $matches); $this->length = filter_var( $matches[1] ?? '', FILTER_VALIDATE_INT, ['options' => ['default' => 15]] ); return true; } public function stream_read($count): string|false { echo 'called `' . __METHOD__ . '` with ' . json_encode(func_get_args()) . PHP_EOL; echo "\tcurrent counter: {$this->counter}" . PHP_EOL; $fizzbuzz = match (true) { $this->counter % 15 === 0 => 'FizzBuzz', $this->counter % 5 === 0 => 'Buzz', $this->counter % 3 === 0 => 'Fizz', default => (string)$this->counter }; $contents = ''; if ($this->counter === 1) { $contents = '<?php ' . PHP_EOL; } $contents .= "echo '{$fizzbuzz}' . PHP_EOL;"; $this->counter++; return $contents; } public function stream_close(): bool { echo 'called `' . __METHOD__ . '` with ' . json_encode(func_get_args()) . PHP_EOL; return true; } public function stream_eof(): bool { echo 'called `' . __METHOD__ . '` with ' . json_encode(func_get_args()) . PHP_EOL; echo "\tcurrent counter: {$this->counter}" . PHP_EOL; return $this->counter ===$this->length; } public function stream_stat(): array|false { echo 'called `' . __METHOD__ . '` with ' . json_encode(func_get_args()) . PHP_EOL; return ['size' => $this->getSize()]; } public function stream_set_option(int $option, int $arg1, int $arg2) { echo 'called `' . __METHOD__ . '` with ' . json_encode(func_get_args()) . PHP_EOL; return false; } private function getSize() { $ret = strlen("<?php \n") + $this->length * 18; $range = range(1, $this->length); $numbers = array_filter($range, fn ($n) => ($n % 3 !== 0 && $n % 5 !== 0)); $ret += strlen(implode('', $numbers)); $fizzOrBuzzs = array_filter($range, fn ($n) => ($n % 15 !== 0) && ($n % 3 === 0 || $n % 5 === 0)); $ret += strlen('fizz') * count($fizzOrBuzzs); $fizzbuzzs = array_filter($range, fn ($n) => ($n % 15 === 0)); $ret += strlen('fizzbuzz') * count($fizzbuzzs); return $ret; } }
Output for git.master, git.master_jit
/bin/php-git-master: error while loading shared libraries: libonig.so.5: cannot open shared object file: No such file or directory
Process exited with code 127.
Output for rfc.property-hooks
called `FizzBuzzStreamWrapper::stream_open` with ["fizzbuzz:\/\/3","rb",65665,null] called `FizzBuzzStreamWrapper::stream_set_option` with [2,0,8192] called `FizzBuzzStreamWrapper::stream_stat` with [] called `FizzBuzzStreamWrapper::stream_read` with [8192] current counter: 1 called `FizzBuzzStreamWrapper::stream_eof` with [] current counter: 2 called `FizzBuzzStreamWrapper::stream_read` with [8192] current counter: 2 called `FizzBuzzStreamWrapper::stream_eof` with [] current counter: 3 called `FizzBuzzStreamWrapper::stream_read` with [8192] current counter: 3 called `FizzBuzzStreamWrapper::stream_eof` with [] current counter: 4 called `FizzBuzzStreamWrapper::stream_close` with [] 1 2 Fizz

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:
25.44 ms | 408 KiB | 5 Q