Skip to content

Commit 1e7afbd

Browse files
Girgiasramsey
authored andcommitted
Revert "Fix GH-8563 Different results for seek() on SplFileObject and SplTempFileObject"
Although the fix is partially correct it also breaks long standing behaviour which has been produced since PHP 5.3. This reverts commit 6f87a5c. This was cherry-picked to PHP-8.1.8 from 79a2832
1 parent 7e8ad57 commit 1e7afbd

9 files changed

+16
-139
lines changed

ext/spl/spl_directory.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,21 +1891,22 @@ static zend_result spl_filesystem_file_read_ex(spl_filesystem_object *intern, bo
18911891
}
18921892

18931893
if (!buf) {
1894-
return FAILURE;
1895-
}
1896-
1897-
if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_DROP_NEW_LINE)) {
1898-
if (line_len > 0 && buf[line_len - 1] == '\n') {
1899-
line_len--;
1900-
if (line_len > 0 && buf[line_len - 1] == '\r') {
1894+
intern->u.file.current_line = estrdup("");
1895+
intern->u.file.current_line_len = 0;
1896+
} else {
1897+
if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_DROP_NEW_LINE)) {
1898+
if (line_len > 0 && buf[line_len - 1] == '\n') {
19011899
line_len--;
1900+
if (line_len > 0 && buf[line_len - 1] == '\r') {
1901+
line_len--;
1902+
}
1903+
buf[line_len] = '\0';
19021904
}
1903-
buf[line_len] = '\0';
19041905
}
1905-
}
19061906

1907-
intern->u.file.current_line = buf;
1908-
intern->u.file.current_line_len = line_len;
1907+
intern->u.file.current_line = buf;
1908+
intern->u.file.current_line_len = line_len;
1909+
}
19091910
intern->u.file.current_line_num += line_add;
19101911

19111912
return SUCCESS;

ext/spl/tests/SplFileObject/fgetcsv_file_empty_lines.phpt

Lines changed: 0 additions & 38 deletions
This file was deleted.

ext/spl/tests/SplFileObject/foreach_file_empty_lines.phpt

Lines changed: 0 additions & 37 deletions
This file was deleted.

ext/spl/tests/SplFileObject/gh8563.phpt

Lines changed: 0 additions & 48 deletions
This file was deleted.

ext/spl/tests/SplFileObject/SplFileObject_fgetcsv_basic.phpt renamed to ext/spl/tests/SplFileObject_fgetcsv_basic.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ fclose($fp);
1313

1414
$fo = new SplFileObject('SplFileObject__fgetcsv1.csv');
1515
var_dump($fo->fgetcsv());
16-
var_dump($fo->fgetcsv());
1716
?>
1817
--CLEAN--
1918
<?php
@@ -30,4 +29,3 @@ array(4) {
3029
[3]=>
3130
string(1) "5"
3231
}
33-
bool(false)

ext/spl/tests/SplFileObject/SplFileObject_key_error001.phpt renamed to ext/spl/tests/SplFileObject_key_error001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ var_dump($s->key());
1818
var_dump($s->valid());
1919
?>
2020
--EXPECT--
21-
int(12)
21+
int(14)
2222
bool(false)

ext/spl/tests/SplFileObject/SplFileObject_key_error002.phpt renamed to ext/spl/tests/SplFileObject_key_error002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ var_dump($s->key());
1818
var_dump($s->valid());
1919
?>
2020
--EXPECT--
21-
int(12)
21+
int(13)
2222
bool(false)

ext/spl/tests/bug81477.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ string(8) "baz,bat
2121
"
2222
string(10) "more,data
2323
"
24+
string(0) ""
2425
--CLEAN--
2526
<?php
2627
@unlink(__DIR__ . '/bug81477.csv');

ext/spl/tests/fileobject_001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ string(1) "4"
7070
int(5)
7171
string(1) "5"
7272
int(6)
73-
bool(false)
73+
string(0) ""
7474
===B===
7575
int(0)
7676
string(1) "0"

0 commit comments

Comments
 (0)