Skip to content

SplFileObject::__toString() reads next line #9883

Closed
@cmb69

Description

@cmb69

Description

The following code:

<?php
$file_stream = new SplFileObject(__FILE__, 'rb');

echo $file_stream; // line 4
echo $file_stream; // line 5
echo $file_stream; // line 6
echo $file_stream; // line 7
echo $file_stream; // line 8
echo $file_stream; // line 9

Resulted in this output:

<?php

$file_stream = new SplFileObject(__FILE__, 'rb');

echo $file_stream; // line 4
echo $file_stream; // line 5

But I expected this output instead:

<?php
<?php
<?php
<?php
<?php
<?php

See https://3v4l.org/gF4tm.

The issue is due to the erroneous fix of bug 77024, where ::__toString() is now an alias of ::fgets() what appears to be strange.

This issue has been discovered by @derickr.

PHP Version

PHP 8.0

Operating System

any

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions