diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 02e61b40060e0..c7dd8b472173f 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -2738,7 +2738,9 @@ PHP_METHOD(SplFileObject, seek) } if (line_pos > 0) { intern->u.file.current_line_num++; - spl_filesystem_file_free_line(intern); + if (!SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_AHEAD)) { + spl_filesystem_file_free_line(intern); + } } } /* }}} */ diff --git a/ext/spl/tests/SplFileObject_next_variation002.phpt b/ext/spl/tests/SplFileObject_next_variation002.phpt index e4903dce0cd23..d48ff8c22371c 100644 --- a/ext/spl/tests/SplFileObject_next_variation002.phpt +++ b/ext/spl/tests/SplFileObject_next_variation002.phpt @@ -26,5 +26,5 @@ echo $s->current(); --EXPECT-- //line 3 //line 4 +//line 3 //line 4 -//line 5 diff --git a/ext/spl/tests/bug81477.phpt b/ext/spl/tests/bug81477.phpt new file mode 100644 index 0000000000000..f7730a791aa03 --- /dev/null +++ b/ext/spl/tests/bug81477.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #81477 (LimitIterator + SplFileObject regression in 8.0.1) +--FILE-- +setFlags(SplFileObject::READ_AHEAD); +$limitIter = new LimitIterator($sfo, 1, -1); + +foreach($limitIter as $row) { + var_dump($row); +} +?> +--EXPECT-- +string(8) "baz,bat +" +string(10) "more,data +" +string(0) "" +--CLEAN-- +