Bug #77024 [Opn->Csd]: SplFileObject::__toString() may return array
| From: | petk@php.net | Date: | Sat, 27 Apr 2019 22:52:13 +0000 |
| Subject: | Bug #77024 [Opn->Csd]: SplFileObject::__toString() may return array | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-220628@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77024&edit=1
ID: 77024
Updated by: petk@php.net
Reported by: cmb@php.net
Summary: SplFileObject::__toString() may return array
-Status: Open
+Status: Closed
Type: Bug
Package: SPL related
Operating System: *
PHP Version: master-Git-2018-10-16 (Git)
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2019-02-11 20:18:14] 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
------------------------------------------------------------------------
[2018-10-16 12:41:30] cmb@php.net
echo $file;
issues an recoverable fatal error:
Method SplTempFileObject::__toString() must return a string value in %s
------------------------------------------------------------------------
[2018-10-16 12:37:13] spam2 at rhsoft dot net
with strict-types this should even trigger a type-error
------------------------------------------------------------------------
[2018-10-16 12:33:45] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77024&edit=1