Bug #72182 [NEW]: \SplFileObject::getSize() returns 0 for files created with tempnam()
| From: | bishop@php.net | Date: | Mon, 09 May 2016 18:11:11 +0000 |
| Subject: | Bug #72182 [NEW]: \SplFileObject::getSize() returns 0 for files created with tempnam() | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-200970@lists.php.net to get a copy of this message | ||
From: bishop
Operating system: Linux 4.1.17-22.30.amzn1.x86_64
PHP version: 5.6.21
Package: SPL related
Bug Type: Bug
Bug description:\SplFileObject::getSize() returns 0 for files created with tempnam()
Description:
------------
\SplFileObject does not seem to treat file names created by tempnam()
the same as file names created manually. In the latter case,
\SplFileObject::getSize() reports the correct on-disk size during write
operations as well as subsequent reads. The former case, however,
returns 0 consistently.
HHVM appears to operate as expected.
See also https://3v4l.org/vLlb0
Test script:
---------------
$paths = [
sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'bishop',
tempnam(sys_get_temp_dir(), 'bishop'),
];
foreach ($paths as $path) {
$fileW = new \SplFileObject($path, 'w');
$fileW->fputcsv(range(0,2));
assert(6 === $fileW->getSize());
echo $fileW->getSize() . PHP_EOL;
$fileR = new \SplFileObject($path, 'r');
assert(6 === $fileR->getSize());
echo $fileR->getSize() . PHP_EOL;
}
Expected result:
----------------
6
6
6
6
Actual result:
--------------
6
6
PHP Warning: assert(): Assertion failed ...
0
PHP Warning: assert(): Assertion failed ...
0
--
Edit bug report at https://bugs.php.net/bug.php?id=72182&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72182&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72182&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72182&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72182&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72182&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72182&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72182&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72182&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72182&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72182&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72182&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72182&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72182&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72182&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72182&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72182&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72182&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72182&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72182&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72182&r=mysqlcfg