1
0
mirror of https://github.com/php/php-src.git synced 2026-03-26 01:02:25 +01:00
Files
archived-php-src/ext/spl/tests/SplFileObject_next_variation002.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

31 lines
483 B
PHP

--TEST--
SPL: SplFileObject::next variation 002, read ahead
--CREDITS--
Ricardo Oedietram <ricardo@odracir.nl>
Erwin Poeze <erwin.poeze@gmail.com>
#PFZ June PHP TestFest 2012
--FILE--
<?php
//line 2
//line 3
//line 4
//line 5
$s = new SplFileObject(__FILE__);
$s->seek(2);
echo $s->current();
$s->next();
echo $s->current();
$s->setFlags(SplFileObject::READ_AHEAD);
$s->seek(2);
echo $s->current();
$s->next();
echo $s->current();
?>
--EXPECT--
//line 3
//line 4
//line 4
//line 5