iterator_count() on an SplFileObject runs endlessly
@alexandre-daubois is already working on this.
Since Sep 25, 2025.
- #19957 by @alexandre-daubois — open
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code:
<?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
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the reported PHP snippet with iterator_count() and SplFileObject on an empty file, then inspect the implementation and existing tests for these APIs. Done means the call terminates and returns int(0) for the empty file while preserving correct counts for non-empty files.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100