Bug #77828 [NEW]: SplFileObject::seek problems on custom stream wrappers
| From: | alexey dot khokhryakov at gmail dot com | Date: | Sun, 31 Mar 2019 22:32:33 +0000 |
| Subject: | Bug #77828 [NEW]: SplFileObject::seek problems on custom stream wrappers | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-220271@lists.php.net to get a copy of this message | ||
From: alexey dot khokhryakov at gmail dot com
Operating system:
PHP version: 7.2.16
Package: SPL related
Bug Type: Bug
Bug description:SplFileObject::seek problems on custom stream wrappers
Description:
------------
SplFileObject::seek() works wrong for custom stream wrappers. It should
work exactly the same as for native files.
In my example I created simple stream wrapper which just proxies all
calls to native fopen/fread/ftell/feof/fseek/stat functions which
demonstrates the problem.
Test script:
---------------
<?php
file_put_contents($tmpFilename = tempnam(sys_get_temp_dir(), 'test'),
"one line\r\n");
stream_wrapper_register('foo', FooStreamWrapper::class);
foreach ([$tmpFilename, "foo:/{$tmpFilename}"] as $filename) {
$file = new SplFileObject($filename, 'r');
$file->seek($file->getSize());
var_dump($file->key());
}
class FooStreamWrapper {
private $r;
public function stream_open($path, $mode) { $this->r =
fopen(str_replace('foo:/', '', $path), $mode); return true; }
public function stream_read($count) { return fread($this->r,
$count); }
public function stream_tell() { return ftell($this->r); }
public function stream_eof() { return feof($this->r); }
public function stream_seek($offset, $whence) { return
fseek($this->r, $offset, $whence) === 0; }
public function url_stat($path) { return stat(str_replace('foo:/',
'', $path)); }
}
Expected result:
----------------
int(1)
int(1)
Actual result:
--------------
int(1)
int(0)
--
Edit bug report at https://bugs.php.net/bug.php?id=77828&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77828&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77828&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77828&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77828&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77828&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77828&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77828&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77828&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77828&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77828&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77828&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77828&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77828&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77828&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77828&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77828&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77828&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77828&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77828&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77828&r=mysqlcfg