Bug #64919 [Opn->Fbk]: SplFileObject::__toString is not used when casting as string

From: Date: Wed, 25 Mar 2015 22:06:55 +0000
Subject: Bug #64919 [Opn->Fbk]: SplFileObject::__toString is not used when casting as string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191610@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64919&edit=1

 ID:                 64919
 Updated by:         danack@php.net
 Reported by:        stof at notk dot org
 Summary:            SplFileObject::__toString is not used when casting
                     as string
-Status:             Open
+Status:             Feedback
 Type:               Bug
 Package:            SPL related
 PHP Version:        5.4.15
 Block user comment: N
 Private report:     N

 New Comment:

I believe this was fixed by the fix to https://bugs.php.net/bug.php?id=64023. I cannot
reproduce on PHP 5.4.9

I realise that the version listed on the bug report is 5.4.15 - however testing the repro case in http://3v4l.org/9HuIJ seems to indicate that it was fixed in 5.4.7.

Can you update the issue if you think it still is an issue.


Previous Comments:
------------------------------------------------------------------------
[2013-05-24 14:37:42] stof at notk dot org

It might be related to https://bugs.php.net/bug.php?id=64023

------------------------------------------------------------------------
[2013-05-24 14:36:26] stof at notk dot org

Description:
------------
The doc documents SplFileObject::__toString as being an alias for SplFileObject::current.
When calling __toString explicitly, this indeed works (and can return an array when READ_CSV is
used, which seems confusing)
But when casting a SplFileObject to a string, it will return the path to the file, like for the
SplFileInfo parent class.

Test script:
---------------
$tempFile = new \SplTempFileObject();
$tempFile->fwrite('foobar-');
$tempFile->rewind();

echo (string) $tempFile;
echo PHP_EOL;
echo $tempFile->__toString();

Expected result:
----------------
Result according to the doc:

foobar-
foobar-

Actual result:
--------------
php://temp
foobar-


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=64919&edit=1


Thread (4 messages)

« previous php.bugs (#191610) next »