diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index c7dd8b472173f..045aad5bc1b02 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -1939,6 +1939,8 @@ static int spl_filesystem_file_read_line_ex(zval * this_ptr, spl_filesystem_obje /* 1) use fgetcsv? 2) overloaded call the function, 3) do it directly */ if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_READ_CSV) || intern->u.file.func_getCurr->common.scope != spl_ce_SplFileObject) { + spl_filesystem_file_free_line(intern); + if (php_stream_eof(intern->u.file.stream)) { if (!silent) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Cannot read from file %s", intern->file_name); diff --git a/ext/spl/tests/bug75917.phpt b/ext/spl/tests/bug75917.phpt new file mode 100644 index 0000000000000..6a318bc68159d --- /dev/null +++ b/ext/spl/tests/bug75917.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #75917 SplFileObject::seek broken with CSV flags +--FILE-- +fputcsv($row); +} +$tmp->setFlags(0); +$tmp->seek(23); +var_dump($tmp->current()); + +$tmp->setFlags(SplFileObject::READ_CSV | SplFileObject::SKIP_EMPTY); +$tmp->seek(23); +var_dump($tmp->current()); +?> +--EXPECT-- +bool(false) +bool(false)