php.net |  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
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: cmb@php.net Assigned:
Status: Closed Package: SPL related
PHP Version: master-Git-2018-10-16 (Git) OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cmb@php.net
New email:
PHP Version: OS:

 

 [2018-10-16 12:33 UTC] cmb@php.net
Description:
------------
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 <http://php.net/manual/en/splfileobject.tostring.php#123238>.

Test script:
---------------
<?php
$file = new SplTempFileObject;
$file->fputcsv(['foo', 'bar', 'baz']);
$file->rewind();
$file->setFlags(SplFileObject::READ_CSV);
echo gettype($file->__toString());
?>

Expected result:
----------------
string

Actual result:
--------------
array

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

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] cmb@php.net
echo $file;

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

Patch Name: [Bug] 77024 - Correct the behaviour of casting spl files to strings 
On GitHub:  https://github.com/php/php-src/pull/3820
Patch:      https://github.com/php/php-src/pull/3820.patch
 [2019-04-27 22:52 UTC] petk@php.net
Automatic comment on behalf of git@duncanc.co.uk
Revision: http://git.php.net/?p=php-src.git;a=commit;h=91c6fb881e7b98c968d270bdf7f0051b4c2b2c9c
Log: Fix #77024: SplFileObject::__toString() may return array
 [2019-04-27 22:52 UTC] petk@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 10:01:26 2024 UTC