php-src icon indicating copy to clipboard operation
php-src copied to clipboard

SplFileObject: current() returns wrong result after call to next()

Open gabrielpl opened this issue 4 years ago • 2 comments

Description

The following code:

<?php

declare(strict_types=1);

$file = new SplTempFileObject();

// write to file
for ($i = 0; $i < 5; $i++) {
    $file->fwrite("line {$i}" . PHP_EOL);
}

$file->rewind();

$file->next();
echo $file->key(), ': ', $file->current();

Resulted in this output:

1: line 0

But I expected this output instead:

1: line 1

PHP Version

PHP 8.1.6

Operating System

Windows 11

gabrielpl avatar May 16 '22 02:05 gabrielpl

Indeed, this looks wrong. This issue seems to be closely related to #8561.

cmb69 avatar May 16 '22 08:05 cmb69

This issue had already been reported as https://bugs.php.net/bug.php?id=65600.

cmb69 avatar May 16 '22 11:05 cmb69