[php-src] Issue #19942: iterator_count() on an SplFileObject runs endlessly
| From: | pilif | Date: | Wed, 24 Sep 2025 02:53:28 +0000 |
| Subject: | [php-src] Issue #19942: iterator_count() on an SplFileObject runs endlessly | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-250904@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/19942
Author: pilif
### Description
The following code:
```php
<?php
touch("/tmp/empty");
var_dump(iterator_count(new SplFileObject("/tmp/empty", "r")));
```
Resulted in this output:
```
(None. Script runs forever)
```
But I expected this output instead:
```
int(0)
```
It fails on files of any size, but this is the simplest I can reproduce the problem with.
Can reproduce this all the way to PHP 5.6 which is the earliest version I tried
### PHP Version
```plain
PHP 8.4.12 (cli) (built: Sep 8 2025 21:17:50) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.4.12, Copyright (c) Zend Technologies
with Zend OPcache v8.4.12, Copyright (c), by Zend Technologies
```
### Operating System
Tested under Linux and macOS