Skip to content

Commit 96ac919

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix #81477: LimitIterator + SplFileObject regression in 8.0.1
2 parents 41e0081 + ee5711d commit 96ac919

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ PHP NEWS
2525
- SPL:
2626
. Fixed bug #80663 (Recursive SplFixedArray::setSize() may cause double-free).
2727
(cmb, Nikita, Tyson Andre)
28+
. Fixed bug #81477 (LimitIterator + SplFileObject regression in 8.0.1). (cmb)
2829

2930
- XML:
3031
. Fixed bug #70962 (XML_OPTION_SKIP_WHITE strips embedded whitespace).

ext/spl/spl_directory.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2728,7 +2728,9 @@ PHP_METHOD(SplFileObject, seek)
27282728
}
27292729
if (line_pos > 0) {
27302730
intern->u.file.current_line_num++;
2731-
spl_filesystem_file_free_line(intern);
2731+
if (!SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_AHEAD)) {
2732+
spl_filesystem_file_free_line(intern);
2733+
}
27322734
}
27332735
} /* }}} */
27342736

ext/spl/tests/SplFileObject_next_variation002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ echo $s->current();
2626
--EXPECT--
2727
//line 3
2828
//line 4
29+
//line 3
2930
//line 4
30-
//line 5

ext/spl/tests/bug81477.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Bug #81477 (LimitIterator + SplFileObject regression in 8.0.1)
3+
--FILE--
4+
<?php
5+
$filename = __DIR__ . '/bug81477.csv';
6+
7+
$s = fopen($filename, 'w+');
8+
fwrite($s, "foo,bar\nbaz,bat\nmore,data\n");
9+
fclose($s);
10+
11+
$sfo = new SplFileObject($filename);
12+
$sfo->setFlags(SplFileObject::READ_AHEAD);
13+
$limitIter = new LimitIterator($sfo, 1, -1);
14+
15+
foreach($limitIter as $row) {
16+
var_dump($row);
17+
}
18+
?>
19+
--EXPECT--
20+
string(8) "baz,bat
21+
"
22+
string(10) "more,data
23+
"
24+
string(0) ""
25+
--CLEAN--
26+
<?php
27+
@unlink(__DIR__ . '/bug81477.csv');
28+
?>

0 commit comments

Comments
 (0)