3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MemoryFile { private static $data = ""; private static $pos = 0; public function stream_open() { self::$pos = 0; return true; } public function stream_read($count) { return substr(self::$data, (self::$pos += $count) - $count, $count); } public function stream_write($data) { self::$data = substr(self::$data, 0, self::$pos) . $data; self::$pos += strlen($data); return strlen($data); } public function stream_tell() { return self::$pos; } public function stream_eof() { return self::$pos >= strlen(self::$data); } public function stream_stat() { return []; } } stream_wrapper_register("foo", "MemoryFile"); file_put_contents("foo://bar", <<<'PHTML' <?php // view.phtml echo "<html><head><title>$this->data</title></head><body></body></html>"; PHTML ); // View.php class View { private $data = 'test'; public function render() { require 'foo://bar'; } } (new View)->render();

preferences:
69.6 ms | 402 KiB | 5 Q