summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2019-12-17 17:52:18 +0100
committerChristoph M. Becker <cmbecker69@gmx.de>2019-12-17 17:52:18 +0100
commit4cd6d384bde0f0641e88ae5431d5b6bdfff4ac83 (patch)
treeeffb463279748fcb52b70a6ce5ade00320b3f7d6
parente45b613950d17b9a3d510dcc9a39c32117ecc081 (diff)
downloadphp-git-4cd6d384bde0f0641e88ae5431d5b6bdfff4ac83.tar.gz
Fix #78976: SplFileObject::fputcsv returns -1 on failure
`php_stream_write()` returns `-1` on failure now, which has to be catered to by `SplFileObject::fputcsv()` which still is supposed to return `false` on failure.
-rw-r--r--NEWS3
-rw-r--r--ext/spl/spl_directory.c3
-rw-r--r--ext/spl/tests/bug78976.phpt9
3 files changed, 15 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index adc5ae1cc8..39bdee3618 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,9 @@ PHP NEWS
. Fixed bug #78903 (Conflict in RTD key for closures results in crash).
(Nikita)
+- Spl:
+ . Fixed bug #78976 (SplFileObject::fputcsv returns -1 on failure). (cmb)
+
19 Dec 2019, PHP 7.4.1
- Core:
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
index d21d9034cd..0b276fcb42 100644
--- a/ext/spl/spl_directory.c
+++ b/ext/spl/spl_directory.c
@@ -2668,6 +2668,9 @@ SPL_METHOD(SplFileObject, fputcsv)
break;
}
ret = php_fputcsv(intern->u.file.stream, fields, delimiter, enclosure, escape);
+ if (ret < 0) {
+ RETURN_FALSE;
+ }
RETURN_LONG(ret);
}
}
diff --git a/ext/spl/tests/bug78976.phpt b/ext/spl/tests/bug78976.phpt
new file mode 100644
index 0000000000..059807eb74
--- /dev/null
+++ b/ext/spl/tests/bug78976.phpt
@@ -0,0 +1,9 @@
+--TEST--
+Bug #78976 (SplFileObject::fputcsv returns -1 on failure)
+--FILE--
+<?php
+$file = new SplFileObject('php://memory', 'r');
+var_dump($file->fputcsv(['foo', 'bar']));
+?>
+--EXPECT--
+bool(false)