3v4l.org

run code in 300+ PHP versions simultaneously
<?php class File_stream { static $stream; public $context; private $_position; public function __get($name) { $n = "_" . $name; echo " get {$name} = {$this->$n}\n"; return $this->$n; } public function __set($name, $value) { $n = "_" . $name; echo " set {$name} = {$value}\n"; $this->$n = $value; } function stream_open ($path, $mode) { echo " open\n"; if ($mode != 'r' && $mode != 'rb') { return false; } $this->position = 0; return true; } function stream_read ($length) { echo " reading {$length} at {$this->position}\n"; fseek(self::$stream, $this->position); $bytes = fread(self::$stream, $length); $this->position = $this->position + strlen($bytes); echo " read ", strlen($bytes), " bytes\n"; return $bytes; } function stream_tell () { echo " tell\n"; return $this->position; } function stream_eof () { echo " eof\n"; fseek(self::$stream, $this->position); return feof(self::$stream); } function stream_seek ($offset, $whence = SEEK_SET) { echo " seek from {$this->position} to {$offset}\n"; fseek(self::$stream, $this->position); $result = fseek(self::$stream, $offset, $whence); $this->position = ftell(self::$stream); echo " new position is {$this->position}\n"; return $result; } function stream_stat () { echo " stat\n"; return fstat(self::$stream); } } stream_wrapper_register('request-file', 'File_stream'); $data = '0123456789abcdef'; $stream_direct = fopen('php://temp', 'w+b'); fwrite($stream_direct, $data); rewind($stream_direct); File_stream::$stream = $stream_direct; $stream = fopen('request-file://', 'r'); echo "read 3 =\n", fread($stream, 3), "\n"; echo "tell =\n", ftell($stream), "\n"; echo "seek -1\n"; fseek($stream, -1, SEEK_CUR); echo "tell =\n", ftell($stream), "\n"; echo "read 2 =\n", fread($stream, 2), "\n"; echo "tell =\n", ftell($stream), "\n"; fclose($stream);
Output for 5.5.0 - 5.5.37, 5.6.0 - 5.6.23, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
open set position = 0 read 3 = get position = 0 reading 8192 at 0 get position = 0 get position = 0 set position = 16 read 16 bytes eof get position = 16 012 tell = 3 seek -1 get position = 16 seek from 16 to 2 get position = 16 set position = 2 get position = 2 new position is 2 tell = 3 read 2 = get position = 2 reading 8192 at 2 get position = 2 get position = 2 set position = 16 read 14 bytes eof get position = 16 23 tell = 5
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 open set position = 0 read 3 = get position = 0 reading 8192 at 0 get position = 0 get position = 0 set position = 16 read 16 bytes eof get position = 16 012 tell = 3 seek -1 get position = 16 seek from 16 to 2 get position = 16 set position = 2 get position = 2 new position is 2 tell = 3 read 2 = get position = 2 reading 8192 at 2 get position = 2 get position = 2 set position = 16 read 14 bytes eof get position = 16 23 tell = 5

preferences:
202.88 ms | 403 KiB | 260 Q