Bug #72182 [Com]: \SplFileObject::getSize() returns 0 for files created with tempnam()
| From: | bishop@php.net | Date: | Mon, 09 May 2016 18:33:41 +0000 |
| Subject: | Bug #72182 [Com]: \SplFileObject::getSize() returns 0 for files created with tempnam() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200971@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72182&edit=1
ID: 72182
Comment by: bishop@php.net
Reported by: bishop@php.net
Summary: \SplFileObject::getSize() returns 0 for files
created with tempnam()
Status: Open
Type: Bug
Package: SPL related
PHP Version: 5.5.0-5.6.21, 7.0.0-7.0.6
Block user comment: N
Private report: N
New Comment:
To clarify, if one adds clearstatcache() before the getSize() calls, then the output is as expected:
6
6
6
6
The gist of this bug report is that the behavior of getSize() for file names created by tempnam()
and file names created manually should be the same. Both should require clearstatcache, or neither
should require.
Previous Comments:
------------------------------------------------------------------------
[2016-05-09 18:11:07] bishop@php.net
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 this bug report at https://bugs.php.net/bug.php?id=72182&edit=1