php / php/php-src

User code can run after module request shutdown via the output layer

未关闭
#20,727 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@ndossche 已经在做这个了。

开始于 2026年1月3日。

  • #20824 来自 @ndossche —— 未关闭
Bug Category: Engine Status: Verified
主要语言
C
星标
40.4k
派生
8.1k
平均合并
2 天 13 小时
30 天内合并 PR
96

描述

Description

The following code:

<?php
header_register_callback( fn() => mb_detect_encoding('foo') );

Resulted in this output:

Fatal error: Uncaught ValueError: mb_detect_encoding(): Argument #2 ($encodings) must specify at least one encoding in /in/0EDPU:2
Stack trace:
#0 /in/0EDPU(2): mb_detect_encoding('foo')
#1 [internal function]: {closure:/in/0EDPU:2}()
#2 {main}
  thrown in /in/0EDPU on line 2

But I expected this output instead:

The error seems to be present since PHP 8.0.0
https://3v4l.org/0EDPU

The error also occurs when mb_convert_encoding() is called instead of mb_detect_encoding().

Workaround

Setting mbstring.detect_order explicitly in php.ini prevents the error:

; php.ini
mbstring.detect_order = "ASCII,UTF-8";

Setting the order with mb_detect_order() inside the callback also prevents the issue:

header_register_callback( function() {
    mb_detect_order(['ASCII', 'UTF-8']);
    mb_detect_encoding('foo');
} );

Setting the order outside of the callback or setting it with ini_set() did not prevent the error.

PHP Version
PHP 8.4.15 (cli) (built: Dec  8 2025 22:51:21) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.4.15, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.15, Copyright (c), by Zend Technologies
    with Xdebug v3.5.0, Copyright (c) 2002-2025, by Derick Rethans
Operating System

No response

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先使用 mb_detect_encoding() 重现 header_register_callback 示例,并将其与文档中记录的预期空输出进行比较。阅读讨论和链接的 pull request #20824,然后验证 callback 在 module request shutdown 后不再运行用户代码,并且重现过程不再输出 fatal error。

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

评估

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

把新 issue 发到你的邮箱

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