Bug #77024 [Opn]: SplFileObject::__toString() may return array

From: Date: Tue, 16 Oct 2018 12:41:30 +0000
Subject: Bug #77024 [Opn]: SplFileObject::__toString() may return array
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217595@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:         cmb@php.net
 Reported by:        cmb@php.net
 Summary:            SplFileObject::__toString() may return array
 Status:             Open
 Type:               Bug
 Package:            SPL related
 Operating System:   *
 PHP Version:        master-Git-2018-10-16 (Git)
 Block user comment: N
 Private report:     N

 New Comment:

echo $file;

issues an recoverable fatal error:
Method SplTempFileObject::__toString() must return a string value in %s


Previous Comments:
------------------------------------------------------------------------
[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


Thread (4 messages)

« previous php.bugs (#217595) next »