User code can run after module request shutdown via the output layer
- Ngôn ngữ chính
- C
- Star
- 40.4k
- Fork
- 8.1k
- Merge trung bình
- 2 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 96
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện ví dụ header_register_callback với mb_detect_encoding() và so sánh với đầu ra rỗng dự kiến được ghi trong tài liệu. Đọc phần thảo luận và pull request #20824 được liên kết, sau đó xác minh rằng callback không còn chạy mã người dùng sau khi module request shutdown và việc tái hiện không còn phát ra lỗi fatal.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- php
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 25/100