[php-src] Issue #9883: SplFileObject::__toString() reads next line
| From: | cmb69 | Date: | Thu, 03 Nov 2022 11:02:09 +0000 |
| Subject: | [php-src] Issue #9883: SplFileObject::__toString() reads next line | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-242742@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/9883
Author: cmb69
### Description
The following code:
```php
<?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](https://github.com/php/php-src/pull/3820) of [bug
77024](http://bugs.php.net/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