php / php/php-src

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

Aperta
#20,727 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@ndossche ci sta già lavorando.

Dal 3/1/2026.

  • #20824 di @ndossche — aperta
Bug Category: Engine Status: Verified
Lingua principale
C
Stelle
40.4k
Fork
8.1k
Merge medio
2g 13h
PR unite (30g)
96

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo l'esempio di header_register_callback con mb_detect_encoding() e confrontalo con l'output vuoto atteso documentato. Leggi la discussione e la pull request #20824 collegata, quindi verifica che il callback non esegua più codice dell'utente dopo l'arresto della richiesta del modulo e che la riproduzione non emetta più l'errore fatale.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
php
Ambito
backend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.