From 91c6fb881e7b98c968d270bdf7f0051b4c2b2c9c Mon Sep 17 00:00:00 2001 From: Craig Duncan Date: Sun, 28 Apr 2019 00:44:48 +0200 Subject: [PATCH] Fix #77024: SplFileObject::__toString() may return array - Correct the behaviour of casting spl files to strings - Add a test for Bug 77024 --- ext/spl/spl_directory.c | 2 +- ext/spl/tests/bug77024.phpt | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 ext/spl/tests/bug77024.phpt diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 47b3521d63..4f274641e8 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -3111,7 +3111,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 }; diff --git a/ext/spl/tests/bug77024.phpt b/ext/spl/tests/bug77024.phpt new file mode 100644 index 0000000000..d61dc941d4 --- /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 -- 2.40.0