Skip to content

Commit 188b1d4

Browse files
committed
SplFileObject::fgetcsv(): Consistently return false on failure
Both the documentation and the stubs state that this method is supposed to return false on failure. However, if the line read (rather than the getcsv operation) fails, it would incorrectly return null instead.
1 parent 2ad97f5 commit 188b1d4

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

ext/spl/spl_directory.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -2345,7 +2345,9 @@ PHP_METHOD(SplFileObject, fgetcsv)
23452345
case 0:
23462346
break;
23472347
}
2348-
spl_filesystem_file_read_csv(intern, delimiter, enclosure, escape, return_value);
2348+
if (spl_filesystem_file_read_csv(intern, delimiter, enclosure, escape, return_value) == FAILURE) {
2349+
RETURN_FALSE;
2350+
}
23492351
}
23502352
/* }}} */
23512353

ext/spl/spl_directory_arginfo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 00139cce188b3950e5a7606c70c5848c6280851d */
2+
* Stub hash: bea6fbfdd7ff20de998dcd24bef4fd2ab56d5041 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SplFileInfo___construct, 0, 0, 1)
55
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)

ext/spl/tests/SplFileObject_fgetcsv_basic.phpt

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ fclose($fp);
1313

1414
$fo = new SplFileObject('SplFileObject__fgetcsv1.csv');
1515
var_dump($fo->fgetcsv());
16+
var_dump($fo->fgetcsv());
17+
var_dump($fo->fgetcsv());
1618
?>
1719
--CLEAN--
1820
<?php
@@ -29,3 +31,8 @@ array(4) {
2931
[3]=>
3032
string(1) "5"
3133
}
34+
array(1) {
35+
[0]=>
36+
NULL
37+
}
38+
bool(false)

0 commit comments

Comments
 (0)