Skip to content

SplFileObject: key() and current() unsinchronized after call to fgets() #8561

Description

@gabrielpl

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();

// read first line
$file->fgets();

// where am I?
echo $file->key(), ': ', $file->current();

Resulted in this output:

1: line 0

But I expected this output instead:

1: line 1

This bug was introduced after fixing #8273

PHP Version

PHP 8.1.6

Operating System

Windows 11

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions