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 git.master, git.master_jit
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 rfc.literals
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?

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:
41.97 ms | 528 KiB | 12 Q