Skip to content

Commit 79a2832

Browse files
committed
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.
1 parent 8fce70a commit 79a2832

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
@@ -1883,21 +1883,22 @@ static zend_result spl_filesystem_file_read_ex(spl_filesystem_object *intern, bo
18831883
}
18841884

18851885
if (!buf) {
1886-
return FAILURE;
1887-
}
1888-
1889-
if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_DROP_NEW_LINE)) {
1890-
if (line_len > 0 && buf[line_len - 1] == '\n') {
1891-
line_len--;
1892-
if (line_len > 0 && buf[line_len - 1] == '\r') {
1886+
intern->u.file.current_line = estrdup("");
1887+
intern->u.file.current_line_len = 0;
1888+
} else {
1889+
if (SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_DROP_NEW_LINE)) {
1890+
if (line_len > 0 && buf[line_len - 1] == '\n') {
18931891
line_len--;
1892+
if (line_len > 0 && buf[line_len - 1] == '\r') {
1893+
line_len--;
1894+
}
1895+
buf[line_len] = '\0';
18941896
}
1895-
buf[line_len] = '\0';
18961897
}
1897-
}
18981898

1899-
intern->u.file.current_line = buf;
1900-
intern->u.file.current_line_len = line_len;
1899+
intern->u.file.current_line = buf;
1900+
intern->u.file.current_line_len = line_len;
1901+
}
19011902
intern->u.file.current_line_num += line_add;
19021903

19031904
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-
NULL

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)