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 git.master, git.master_jit, rfc.property-hooks
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

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:
60.13 ms | 402 KiB | 8 Q