3v4l.org

run code in 300+ PHP versions simultaneously
<?php \spl_autoload_register(function($class) { echo "Autoloader for '$class' called\n"; class_alias(Test::class, $class); return true; }); class Test { static function blubb() { echo static::class, "\n"; } } class MyStreamWrapper { static $counter = 1; private $id; public function __construct() { $this->id = self::$counter++; } public function stream_open($path, $mode, $options, &$opened_path) { echo "({$this->id}) stream_open()\n"; return true; } public function stream_write($data) { echo "({$this->id}) stream_write()\n"; return \strlen($data); } public function stream_flush() { echo "({$this->id}) stream_flush()\n"; if ($this->id === 1) { Lalala::blubb(); } else { Foobar::blubb(); } return true; } public function stream_close() { echo "({$this->id}) stream_close()\n"; return true; } public function __destruct() { echo "({$this->id}) __destruct()\n"; } } \stream_wrapper_register('test', MyStreamWrapper::class); if (($handle = \fopen('test:///foobar', 'r+')) === false) { throw new \RuntimeException("Failed to open file"); } if (\fwrite($handle, 'test') === false) { throw new \RuntimeException("Failed to write to file"); } if (\fclose($handle) === false) { throw new \RuntimeException("Failed to close file"); } if (($handle2 = \fopen('test:///blubb', 'r+')) === false) { throw new \RuntimeException("Failed to open file"); } if (\fwrite($handle2, 'test') === false) { throw new \RuntimeException("Failed to write to file"); }
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: Creation of dynamic property MyStreamWrapper::$context is deprecated in /in/GB7Mm on line 67 (1) stream_open() (1) stream_write() (1) stream_flush() Autoloader for 'Lalala' called Test (1) stream_close() (1) __destruct() Deprecated: Creation of dynamic property MyStreamWrapper::$context is deprecated in /in/GB7Mm on line 79 (2) stream_open() (2) stream_write() (2) __destruct() (2) stream_flush() Fatal error: Uncaught Error: Class "Foobar" not found in /in/GB7Mm:47 Stack trace: #0 [internal function]: MyStreamWrapper->stream_flush() #1 {main} thrown in /in/GB7Mm on line 47
Process exited with code 255.
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 MyStreamWrapper::$context is deprecated in /in/GB7Mm on line 67 (1) stream_open() (1) stream_write() (1) stream_flush() Autoloader for 'Lalala' called Test (1) stream_close() (1) __destruct() Deprecated: Creation of dynamic property MyStreamWrapper::$context is deprecated in /in/GB7Mm on line 79 (2) stream_open() (2) stream_write() (2) __destruct() (2) stream_flush() Fatal error: Uncaught Error: Class "Foobar" not found in /in/GB7Mm:47 Stack trace: #0 [internal function]: MyStreamWrapper->stream_flush() #1 {main} thrown in /in/GB7Mm on line 47
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
(1) stream_open() (1) stream_write() (1) stream_flush() Autoloader for 'Lalala' called Test (1) stream_close() (1) __destruct() (2) stream_open() (2) stream_write() (2) __destruct() (2) stream_flush() Fatal error: Uncaught Error: Class "Foobar" not found in /in/GB7Mm:47 Stack trace: #0 [internal function]: MyStreamWrapper->stream_flush() #1 {main} thrown in /in/GB7Mm on line 47
Process exited with code 255.
Output for 7.3.32 - 7.3.33, 7.4.33
(1) stream_open() (1) stream_write() (1) stream_flush() Autoloader for 'Lalala' called Test (1) stream_close() (1) __destruct() (2) stream_open() (2) stream_write() (2) __destruct() (2) stream_flush() Fatal error: Uncaught Error: Class 'Foobar' not found in /in/GB7Mm:47 Stack trace: #0 [internal function]: MyStreamWrapper->stream_flush() #1 {main} thrown in /in/GB7Mm on line 47
Process exited with code 255.
Output for 7.0.6 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.32
(1) stream_open() (1) stream_write() (1) stream_flush() Autoloader for 'Lalala' called Test (1) stream_close() (1) __destruct() (2) stream_open() (2) stream_write() (2) __destruct() (2) stream_flush() Warning: spl_autoload(): open_basedir restriction in effect. File(foobar.inc) is not within the allowed path(s): (/tmp:/in:/etc) in /in/GB7Mm on line 47 Warning: spl_autoload(): open_basedir restriction in effect. File(foobar.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/GB7Mm on line 47 Fatal error: Uncaught Error: Class 'Foobar' not found in /in/GB7Mm:47 Stack trace: #0 [internal function]: MyStreamWrapper->stream_flush() #1 {main} thrown in /in/GB7Mm on line 47
Process exited with code 255.
Output for 7.0.0 - 7.0.5
(1) stream_open() (1) stream_write() (1) stream_flush() Autoloader for 'Lalala' called Test (1) stream_close() (1) __destruct() (2) stream_open() (2) stream_write() (2) __destruct() (2) stream_flush() Warning: spl_autoload(): open_basedir restriction in effect. File(foobar.inc) is not within the allowed path(s): (/tmp:/in:/etc) in /in/GB7Mm on line 47 Warning: spl_autoload(): open_basedir restriction in effect. File(foobar.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/GB7Mm on line 47 Fatal error: Uncaught LogicException: Class Foobar could not be loaded in /in/GB7Mm:47 Stack trace: #0 [internal function]: spl_autoload('Foobar') #1 /in/GB7Mm(47): spl_autoload_call('Foobar') #2 [internal function]: MyStreamWrapper->stream_flush() #3 {main} thrown in /in/GB7Mm on line 47
Process exited with code 255.
Output for 5.6.0 - 5.6.40
(1) stream_open() (1) stream_write() (1) stream_flush() Autoloader for 'Lalala' called Test (1) stream_close() (1) __destruct() (2) stream_open() (2) stream_write() (2) __destruct() (2) stream_flush() Warning: spl_autoload(): open_basedir restriction in effect. File(foobar.inc) is not within the allowed path(s): (/tmp:/in:/etc) in /in/GB7Mm on line 47 Warning: spl_autoload(): open_basedir restriction in effect. File(foobar.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/GB7Mm on line 47 Fatal error: Uncaught exception 'LogicException' with message 'Class Foobar could not be loaded' in /in/GB7Mm:47 Stack trace: #0 [internal function]: spl_autoload('Foobar') #1 /in/GB7Mm(47): spl_autoload_call('Foobar') #2 [internal function]: MyStreamWrapper->stream_flush() #3 {main} thrown in /in/GB7Mm on line 47
Process exited with code 255.

preferences:
237.33 ms | 402 KiB | 284 Q