Bug #64811 [NEW]: SplTempFileObject doesn't provide valid return values for SplFileInfo / filenam
From: bugs+php at childno dot de
Operating system: Any
PHP version: 5.4.15
Package: SPL related
Bug Type: Bug
Bug description:SplTempFileObject doesn't provide valid return values for SplFileInfo / filenam
Description:
------------
the SplTempFileObject is intended to use the php://temp in-memory storage.
This has disadvantages if it is used for creating files on the fly that
needed to be processed afterwards. Typically you want to provide
SplFileInfo to certain interfaces that might handle and read the content
again.
e.g. see
http://stackoverflow.com/questions/12555139
Test script:
---------------
$file = new \SplTempFileObject();
if ($file->fwrite("foo") !== null)
print('wrote ' . $file->ftell() . ' byte(s) to `' .
$file->getRealPath() . '`');
// wrote 3 byte(s) to ``
// ^^ thats ok for < 2MB while it is expected to be in-memory
$file = new \SplTempFileObject(0);
if ($file->fwrite("foo") !== null)
print('wrote ' . $file->ftell() . ' byte(s) to `' .
$file->getRealPath() . '`');
// wrote 3 byte(s) to ``
// NOT OK Because we set the limit to 0 to force writing stuff to the
filesystem
$file = new \SplFileObject(tempnam(sys_get_temp_dir(), rand()), 'w+');
if ($file->fwrite("bar") !== null)
print('wrote ' . $file->ftell() . ' byte(s) to `' .
$file->getRealPath() . '`');
// wrote 3 byte(s) to /tmp/2123740490ZwI6Qd
// ^^ that's what I expect even for \SplTempFileObject(0)
Expected result:
----------------
\SplTempFileObject->getFileName() should return s.th. like
2123740490ZwI6Qd \SplTempFileObject->getFileInfo() should return a valid
SplFileInfo Object pointing to /tmp/2123740490ZwI6Qd
\SplTempFileObject->getRealPath() should return s.th. like
/tmp/2123740490ZwI6Qd
Actual result:
--------------
\SplTempFileObject->getFileName() will return php://temp
\SplTempFileObject->getFileInfo() will return an empty object / file
pointer \SplTempFileObject->getRealPath() will always return an empty
string!
--
Edit bug report at https://bugs.php.net/bug.php?id=64811&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=64811&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=64811&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=64811&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=64811&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=64811&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=64811&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=64811&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=64811&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=64811&r=support
Expected behavior: https://bugs.php.net/fix.php?id=64811&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=64811&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=64811&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=64811&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64811&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=64811&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=64811&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=64811&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=64811&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=64811&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=64811&r=mysqlcfg
Thread (2 messages)
- bugs+php at childno dot de