3v4l.org

run code in 300+ PHP versions simultaneously
<?php $txt = <<<TXT 1 Hello! 2 How 3 are 4 you? TXT; class FileObject extends SplFileObject { public function seek($offset) { if ($offset < 0) { throw new Exception("Can't seek file: " . $this->getPathname() . " to negative offset: $offset"); } $this->rewind(); for ($i = 0; $i < $offset; $i++) { $this->current(); $this->next(); if ($this->eof()) { break; } } $this->current(); } } $file = new FileObject('php://memory', 'w+'); $file->fwrite($txt); echo 'Seeking line 1...', PHP_EOL; $file->seek(0); echo 'Position in the file: ', $file->ftell(), PHP_EOL; echo 'Rest of the file: ', PHP_EOL, $file->fread(5000); echo PHP_EOL, '-------------', PHP_EOL; echo 'Seeking line 2...', PHP_EOL; $file->seek(1); echo 'Position in the file: ', $file->ftell(), PHP_EOL; echo 'Rest of the file: ', PHP_EOL, $file->fread(5000);
Output for 8.1.0 - 8.1.2
Deprecated: Return type of FileObject::seek($offset) should either be compatible with SplFileObject::seek(int $line): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/XUPgl on line 12 Seeking line 1... Position in the file: 9 Rest of the file: 2 How 3 are 4 you? ------------- Seeking line 2... Position in the file: 15 Rest of the file: 3 are 4 you?
Output for 5.5.11 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.27, 8.0.0 - 8.0.14
Seeking line 1... Position in the file: 9 Rest of the file: 2 How 3 are 4 you? ------------- Seeking line 2... Position in the file: 15 Rest of the file: 3 are 4 you?
Output for 5.1.4 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.10
Seeking line 1... Position in the file: 9 Rest of the file: Fatal error: Call to undefined method FileObject::fread() in /in/XUPgl on line 37
Process exited with code 255.
Output for 5.1.0 - 5.1.1, 5.1.3
Fatal error: Uncaught exception 'RuntimeException' with message 'SplFileObject::__construct(php://memory): failed to open stream: Success' in /in/XUPgl:31 Stack trace: #0 /in/XUPgl(31): SplFileObject->__construct('php://memory', 'w+') #1 {main} thrown in /in/XUPgl on line 31
Process exited with code 255.
Output for 5.1.2
Fatal error: Uncaught exception 'RuntimeException' with message 'SplFileObject::__construct(php://memory): failed to open stream: Success' in /in/XUPgl:32 Stack trace: #0 /in/XUPgl(32): SplFileObject->__construct('php://memory', 'w+') #1 {main} thrown in /in/XUPgl on line 32
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Fatal error: Class 'SplFileObject' not found in /in/XUPgl on line 10
Process exited with code 255.
Output for 4.4.3 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/XUPgl on line 12
Process exited with code 255.
Output for 4.4.2
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/XUPgl on line 13
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/XUPgl on line 12
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/XUPgl on line 12
Process exited with code 255.

preferences:
64.86 ms | 540 KiB | 12 Q