diff --git a/NEWS b/NEWS index 604945a77c701..18d931bccded7 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 1e84b8beee97a..7f0fcaf8943a8 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 7fda240b7051a..8f94e50ddc861 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 0000000000000..ba59f3388b85e --- /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-- + +--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" +} +