Commit 6b197ee4edf for php.net

commit 6b197ee4edfcd8c9bc2d0cc9d89f663b21187594
Author: Tobias Vorwachs <tobias.vorwachs@eventim.de>
Date:   Tue Nov 18 17:15:06 2025 +0100

    mbstring: fix missing copying of detect_order_list to current_detect_order_list on ini_set('mbstring.detect_order', string)

    Closes GH-20523.

diff --git a/NEWS b/NEWS
index 604945a77c7..18d931bccde 100644
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,10 @@ PHP                                                                        NEWS
   . Fixed bug GH-20483 (ASAN stack overflow with fiber.stack_size INI
     small value). (David Carlier)

+- Mbstring:
+  . ini_set() with mbstring.detect_order changes the order of mb_detect_order
+    as intended, since mbstring.detect_order is an INI_ALL setting. (tobee94)
+
 - Opcache:
   . Fixed bug GH-20051 (apache2 shutdowns when restart is requested during
     preloading). (Arnaud, welcomycozyhom)
diff --git a/UPGRADING b/UPGRADING
index 1e84b8beee9..7f0fcaf8943 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -98,6 +98,13 @@ PHP 8.6 UPGRADE NOTES
     When used along with ZEND_JIT_DEBUG_TRACE_EXIT_INFO, the source of exit
     points is printed in exit info output, in debug builds.

+- Mbstring:
+  . The mbstring.detect_order INI directive now updates the internal detection
+    order when changed at runtime via ini_set(). Previously, runtime changes
+    using ini_set() did not take effect for mb_detect_order(). Setting the
+    directive to NULL or an empty string at runtime now leaves the previously
+    configured detection order unchanged.
+
 ========================================
 12. Windows Support
 ========================================
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index 7fda240b705..8f94e50ddc8 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -718,6 +718,11 @@ static PHP_INI_MH(OnUpdate_mbstring_detect_order)
 	}
 	MBSTRG(detect_order_list) = list;
 	MBSTRG(detect_order_list_size) = size;
+
+	if (stage == PHP_INI_STAGE_RUNTIME) {
+		php_mb_populate_current_detect_order_list();
+	}
+
 	return SUCCESS;
 }
 /* }}} */
@@ -5981,6 +5986,11 @@ static void php_mb_populate_current_detect_order_list(void)
 			entry[i] = mbfl_no2encoding(src[i]);
 		}
 	}
+
+	if (MBSTRG(current_detect_order_list) != NULL) {
+		efree(ZEND_VOIDP(MBSTRG(current_detect_order_list)));
+	}
+
 	MBSTRG(current_detect_order_list) = entry;
 	MBSTRG(current_detect_order_list_size) = nentries;
 }
diff --git a/ext/mbstring/tests/mb_detect_order_with_ini_set.phpt b/ext/mbstring/tests/mb_detect_order_with_ini_set.phpt
new file mode 100644
index 00000000000..ba59f3388b8
--- /dev/null
+++ b/ext/mbstring/tests/mb_detect_order_with_ini_set.phpt
@@ -0,0 +1,60 @@
+--TEST--
+Test mb_detect_order() function : ini set changes order
+--EXTENSIONS--
+mbstring
+--INI--
+mbstring.detect_order=UTF-8,ISO-8859-15,ISO-8859-1,ASCII
+--FILE--
+<?php
+
+var_dump( mb_detect_order());
+
+ini_set('mbstring.detect_order', 'UTF-8, ISO-8859-1, ASCII');
+
+var_dump( mb_detect_order());
+
+ini_set('mbstring.detect_order', 'UTF-8');
+
+var_dump( mb_detect_order());
+
+ini_set('mbstring.detect_order', NULL);
+
+var_dump( mb_detect_order());
+
+ini_set('mbstring.detect_order', '');
+
+var_dump( mb_detect_order());
+
+?>
+--EXPECT--
+array(4) {
+  [0]=>
+  string(5) "UTF-8"
+  [1]=>
+  string(11) "ISO-8859-15"
+  [2]=>
+  string(10) "ISO-8859-1"
+  [3]=>
+  string(5) "ASCII"
+}
+array(3) {
+  [0]=>
+  string(5) "UTF-8"
+  [1]=>
+  string(10) "ISO-8859-1"
+  [2]=>
+  string(5) "ASCII"
+}
+array(1) {
+  [0]=>
+  string(5) "UTF-8"
+}
+array(1) {
+  [0]=>
+  string(5) "UTF-8"
+}
+array(1) {
+  [0]=>
+  string(5) "UTF-8"
+}
+