|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77024 SplFileObject::__toString() may return array
Submitted: 2018-10-16 12:33 UTC Modified: 2018-10-16 12:41 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: Assigned:
Status: Closed Package: SPL related
PHP Version: master-Git-2018-10-16 (Git) OS: *
Private report: No CVE-ID: None
 [2018-10-16 12:33 UTC]
SplFileObject::__toString() is an alias of ::current(), but since
the latter returns an array instead of a string, if the READ_CSV
flag is set, the former also does.  This is at least rather
confusing, since one expects __toString() to return a string.

See also <>.

Test script:
$file = new SplTempFileObject;
$file->fputcsv(['foo', 'bar', 'baz']);
echo gettype($file->__toString());

Expected result:

Actual result:


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-16 12:37 UTC] spam2 at rhsoft dot net
with strict-types this should even trigger a type-error
 [2018-10-16 12:41 UTC]
echo $file;

issues an recoverable fatal error:
Method SplTempFileObject::__toString() must return a string value in %s
 [2019-02-11 20:18 UTC]
The following pull request has been associated:

Patch Name: [Bug] 77024 - Correct the behaviour of casting spl files to strings 
On GitHub:
 [2019-04-27 22:52 UTC]
Automatic comment on behalf of
Log: Fix #77024: SplFileObject::__toString() may return array
 [2019-04-27 22:52 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon May 29 09:03:40 2023 UTC