1
0
mirror of https://github.com/php/php-src.git synced 2026-04-01 21:22:13 +02:00
Files
archived-php-src/ext/spl/tests/bug62004.phpt
Christoph M. Becker f1d11c118d Fix #62004: SplFileObject: fgets after seek returns wrong line
As it is, `::seek(0)` sets the file pointer to the beginning of the
file, but `::seek($n)` where `$n > 0` sets the file pointer to the
beginning of the following line, having line `$n` already read into the
line buffer.  This is pretty inconsistent; we fix it by always seeking
to the beginning of the line.

We also add a test case for the duplicate bug #46569.

Closes GH-6434.
2020-11-30 16:03:37 +01:00

18 lines
308 B
PHP

--TEST--
Bug #62004 (SplFileObject: fgets after seek returns wrong line)
--FILE--
<?php
$f = new SplFileObject(__DIR__ . '/bug62004.txt');
$f->setFlags(SplFileObject::SKIP_EMPTY);
$f->seek(0);
echo $f->fgets();
$f->seek(1);
echo $f->fgets();
$f->seek(2);
echo $f->fgets();
?>
--EXPECT--
Line 1
Line 2
Line 3