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();
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: Creation of dynamic property MemoryFile::$context is deprecated in /in/Qv730 on line 16 Deprecated: Creation of dynamic property MemoryFile::$context is deprecated in /in/Qv730 on line 29 Warning: require(): MemoryFile::stream_set_option is not implemented! in /in/Qv730 on line 29 <html><head><title>test</title></head><body></body></html>
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 Deprecated: Creation of dynamic property MemoryFile::$context is deprecated in /in/Qv730 on line 16 Deprecated: Creation of dynamic property MemoryFile::$context is deprecated in /in/Qv730 on line 29 Warning: require(): MemoryFile::stream_set_option is not implemented! in /in/Qv730 on line 29 <html><head><title>test</title></head><body></body></html>
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Warning: require(): MemoryFile::stream_set_option is not implemented! in /in/Qv730 on line 29 <html><head><title>test</title></head><body></body></html>
Output for 7.4.0 - 7.4.33
Warning: require(): MemoryFile::stream_set_option is not implemented! in /in/Qv730 on line 29 Fatal error: require(): Failed opening required 'foo://bar' (include_path='.:') in /in/Qv730 on line 29
Process exited with code 255.
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
<html><head><title>test</title></head><body></body></html>

preferences:
192.96 ms | 402 KiB | 199 Q