User code can run after module request shutdown via the output layer
- 主要言語
- C
- スター
- 40.4k
- フォーク
- 8.2k
- 平均マージ
- 2日 13時間
- マージ済み PR(30日)
- 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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、mb_detect_encoding() を使用した header_register_callback の例を再現し、ドキュメントに記載された期待される空の出力と比較します。ディスカッションとリンクされている pull request #20824 を読み、その後、モジュールリクエストのシャットダウン後に callback がユーザーコードを実行しなくなったこと、および再現時に fatal error が出力されなくなったことを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- php
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100