[php-src] Issue #8563: Different results for seek() on SplFileObject and SplTempFileObject
| From: | gabrielpl | Date: | Mon, 16 May 2022 03:36:20 +0000 |
| Subject: | [php-src] Issue #8563: Different results for seek() on SplFileObject and SplTempFileObject | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-241523@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8563
Author: gabrielpl
### Description
The following [code](https://3v4l.org/DXe8i):
```php
<?php
declare(strict_types=1);
const LINES = 5;
const INDEX = 10;
$file_01 = new SplTempFileObject();
$file_02 = new SplFileObject('/tmp/test.txt', 'w+');
// write to files
for ($i = 0; $i < LINES; $i++) {
$file_01->fwrite("line {$i}" . PHP_EOL);
$file_02->fwrite("line {$i}" . PHP_EOL);
}
// reset
$file_01->rewind();
$file_02->rewind();
// seek
$file_01->seek(INDEX);
$file_02->seek(INDEX);
// show results
echo 'file_01: ' . $file_01->key(), PHP_EOL;
echo 'file_02: ' . $file_02->key(), PHP_EOL;
```
Resulted in this output:
```
file_01: 4
file_02: 5
```
But I expected this output instead:
```
file_01: 5
file_02: 5
```
### PHP Version
PHP 8.1.6
### Operating System
Windows 11