Skip to content

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

@gabrielpl

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

$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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions