php / php/php-src

iterator_count() on an SplFileObject runs endlessly

未关闭
#19,942 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@alexandre-daubois 已经在做这个了。

开始于 2025年9月25日。

  • #19957 来自 @alexandre-daubois —— 未关闭
Bug Extension: spl Status: Verified
主要语言
C
星标
40.4k
派生
8.1k
平均合并
2 天 13 小时
30 天内合并 PR
96

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,在空文件上使用 iterator_count() 和 SplFileObject 运行报告中的 PHP 代码片段,然后检查这些 API 的实现和现有测试。完成标准是该调用能够终止,并为该空文件返回 int(0),同时对非空文件保持正确的计数。

由索引模型根据 Issue 内容生成。

评估

技术栈
php
领域
backend
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。