From f3e9f441d0de8116269f7d2a4e209e3c25effeaf Mon Sep 17 00:00:00 2001 From: Craig Duncan Date: Mon, 11 Feb 2019 20:11:38 +0000 Subject: [PATCH 1/2] Correct the behaviour of casting spl files to strings --- ext/spl/spl_directory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index bc05044bc72c..23b53644acf9 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -3112,7 +3112,7 @@ static const zend_function_entry spl_SplFileObject_functions[] = { SPL_ME(SplFileObject, seek, arginfo_file_object_seek, ZEND_ACC_PUBLIC) /* mappings */ SPL_MA(SplFileObject, getCurrentLine, SplFileObject, fgets, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC) - SPL_MA(SplFileObject, __toString, SplFileObject, current, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC) + SPL_MA(SplFileObject, __toString, SplFileObject, fgets, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC) PHP_FE_END }; From 7693206a621615e3829e879f5d2ae581e9c7ce4e Mon Sep 17 00:00:00 2001 From: Craig Duncan Date: Mon, 11 Feb 2019 20:11:51 +0000 Subject: [PATCH 2/2] Add a test for Bug 77024 --- ext/spl/tests/bug77024.phpt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 ext/spl/tests/bug77024.phpt diff --git a/ext/spl/tests/bug77024.phpt b/ext/spl/tests/bug77024.phpt new file mode 100644 index 000000000000..d61dc941d4a6 --- /dev/null +++ b/ext/spl/tests/bug77024.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #77024 SplFileObject::__toString() may return array +--FILE-- +fputcsv(['foo', 'bar', 'baz']); +$file->rewind(); +$file->setFlags(SplFileObject::READ_CSV); +echo $file . "\n"; + +$tmp = tempnam(sys_get_temp_dir(), "php-tests-"); +file_put_contents($tmp, "line1\nline2\nline3\n"); +$file = new SplFileObject($tmp); +$file->rewind(); +echo $file . "\n"; +unset($file); +unlink($tmp); + +?> +--EXPECT-- +foo,bar,baz + +line1