Skip to content

Commit 6f32510

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix #75917: SplFileObject::seek broken with CSV flags
2 parents 572c09d + daf79e2 commit 6f32510

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ PHP NEWS
2525
- Reflection:
2626
. Fixed bug #81681 (ReflectionEnum throwing exceptions). (cmb)
2727

28+
- Spl:
29+
. Fixed bug #75917 (SplFileObject::seek broken with CSV flags). (Aliaksandr
30+
Bystry)
31+
2832
02 Dec 2021, PHP 8.1.1
2933

3034
- IMAP:

ext/spl/spl_directory.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,6 +1940,8 @@ static int spl_filesystem_file_read_line_ex(zval * this_ptr, spl_filesystem_obje
19401940

19411941
/* 1) use fgetcsv? 2) overloaded call the function, 3) do it directly */
19421942
if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_CSV) || intern->u.file.func_getCurr->common.scope != spl_ce_SplFileObject) {
1943+
spl_filesystem_file_free_line(intern);
1944+
19431945
if (php_stream_eof(intern->u.file.stream)) {
19441946
if (!silent) {
19451947
zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Cannot read from file %s", ZSTR_VAL(intern->file_name));

ext/spl/tests/bug75917.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #75917 (SplFileObject::seek broken with CSV flags)
3+
--FILE--
4+
<?php
5+
$expected = [
6+
['john', 'doe', '[email protected]', '0123456789'],
7+
['jane', 'doe', '[email protected]'],
8+
];
9+
10+
$tmp = new SplTempFileObject();
11+
foreach ($expected as $row) {
12+
$tmp->fputcsv($row);
13+
}
14+
$tmp->setFlags(0);
15+
$tmp->seek(23);
16+
var_dump($tmp->current());
17+
18+
$tmp->setFlags(SplFileObject::READ_CSV | SplFileObject::SKIP_EMPTY);
19+
$tmp->seek(23);
20+
var_dump($tmp->current());
21+
?>
22+
--EXPECT--
23+
bool(false)
24+
bool(false)

0 commit comments

Comments
 (0)