Skip to content

Commit 91c6fb8

Browse files
duncan3dcpetk
authored andcommitted
Fix #77024: SplFileObject::__toString() may return array
- Correct the behaviour of casting spl files to strings - Add a test for Bug 77024
1 parent 57d5dc5 commit 91c6fb8

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

ext/spl/spl_directory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3111,7 +3111,7 @@ static const zend_function_entry spl_SplFileObject_functions[] = {
31113111
SPL_ME(SplFileObject, seek, arginfo_file_object_seek, ZEND_ACC_PUBLIC)
31123112
/* mappings */
31133113
SPL_MA(SplFileObject, getCurrentLine, SplFileObject, fgets, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
3114-
SPL_MA(SplFileObject, __toString, SplFileObject, current, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
3114+
SPL_MA(SplFileObject, __toString, SplFileObject, fgets, arginfo_splfileinfo_void, ZEND_ACC_PUBLIC)
31153115
PHP_FE_END
31163116
};
31173117

ext/spl/tests/bug77024.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #77024 SplFileObject::__toString() may return array
3+
--FILE--
4+
<?php
5+
6+
$file = new SplTempFileObject;
7+
$file->fputcsv(['foo', 'bar', 'baz']);
8+
$file->rewind();
9+
$file->setFlags(SplFileObject::READ_CSV);
10+
echo $file . "\n";
11+
12+
$tmp = tempnam(sys_get_temp_dir(), "php-tests-");
13+
file_put_contents($tmp, "line1\nline2\nline3\n");
14+
$file = new SplFileObject($tmp);
15+
$file->rewind();
16+
echo $file . "\n";
17+
unset($file);
18+
unlink($tmp);
19+
20+
?>
21+
--EXPECT--
22+
foo,bar,baz
23+
24+
line1

0 commit comments

Comments
 (0)