[php-src] master: Merge branch 'PHP-8.5' into PHP-8.6

From: Date: Tue, 24 Nov 2026 20:55:00 +0000
Subject: [php-src] master: Merge branch 'PHP-8.5' into PHP-8.6
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-144136@lists.php.net to get a copy of this message
Author: Weilin Du (LamentXU123) Date: 2026-11-25T04:53:05+08:00 Commit: https://github.com/php/php-src/commit/f3515f278081e7107c9c7ca7e05eccfa4f82d1ce Raw diff: https://github.com/php/php-src/commit/f3515f278081e7107c9c7ca7e05eccfa4f82d1ce.diff Merge branch 'PHP-8.5' into PHP-8.6 * PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5 Changed paths: A ext/intl/tests/msgfmt_set_pattern_preserves_state.phpt M NEWS M ext/intl/msgformat/msgformat_attr.cpp Diff: diff --git a/NEWS b/NEWS index d32b3654caf4..7de98e000e1b 100644 --- a/NEWS +++ b/NEWS @@ -90,6 +90,8 @@ PHP NEWS . Fixed Locale::lookup() ignoring the default locale when the language tag list is empty. (Weilin Du) . Fixed IntlCalendar::setTime() accepting non-finite timestamps. (Weilin Du) + . Fixed MessageFormatter::setPattern() losing the previous pattern when + the new pattern is invalid. (Weilin Du, David Carlier) - JSON: . Fixed json_decode() and json_validate() error messages. (lacatoire) diff --git a/ext/intl/msgformat/msgformat_attr.cpp b/ext/intl/msgformat/msgformat_attr.cpp index 15c3525b858f..efa2b0128f4b 100644 --- a/ext/intl/msgformat/msgformat_attr.cpp +++ b/ext/intl/msgformat/msgformat_attr.cpp @@ -16,6 +16,10 @@ #include <config.h> #endif +#include <memory> + +#include <unicode/msgfmt.h> + extern "C" { #include "php_intl.h" #include "msgformat_class.h" @@ -78,7 +82,13 @@ U_CFUNC PHP_FUNCTION( msgfmt_set_pattern ) } #endif - umsg_applyPattern(MSG_FORMAT_OBJECT(mfo), spattern, spattern_len, &spattern_error, &INTL_DATA_ERROR_CODE(mfo)); + icu::MessageFormat *mf = reinterpret_cast<icu::MessageFormat *>(MSG_FORMAT_OBJECT(mfo)); + std::unique_ptr<icu::MessageFormat> new_mf(static_cast<icu::MessageFormat *>(mf->clone())); + if (!new_mf) { + INTL_DATA_ERROR_CODE(mfo) = U_MEMORY_ALLOCATION_ERROR; + } else { + new_mf->applyPattern(icu::UnicodeString(spattern, spattern_len), spattern_error, INTL_DATA_ERROR_CODE(mfo)); + } if (spattern) { efree(spattern); } @@ -90,6 +100,9 @@ U_CFUNC PHP_FUNCTION( msgfmt_set_pattern ) RETURN_FALSE; } + delete mf; + MSG_FORMAT_OBJECT(mfo) = reinterpret_cast<UMessageFormat *>(new_mf.release()); + mfo->mf_data.tz_set = 0; if(mfo->mf_data.orig_format) { efree(mfo->mf_data.orig_format); } diff --git a/ext/intl/tests/msgfmt_set_pattern_preserves_state.phpt b/ext/intl/tests/msgfmt_set_pattern_preserves_state.phpt new file mode 100644 index 000000000000..e26b42b3ed35 --- /dev/null +++ b/ext/intl/tests/msgfmt_set_pattern_preserves_state.phpt @@ -0,0 +1,28 @@ +--TEST-- +MessageFormatter::setPattern() preserves the previous pattern on failure +--CREDITS-- +Wong Wai Kin +--EXTENSIONS-- +intl +--FILE-- +<?php +$formatter = new MessageFormatter('en', 'Hello, {0}!'); +var_dump($formatter->format(['world'])); + +var_dump($formatter->setPattern('{0,date')); +var_dump($formatter->getPattern()); +var_dump($formatter->format(['world'])); + +var_dump($formatter->setPattern('{0,number,integer} items')); +var_dump($formatter->format([2])); + +var_dump($formatter->setPattern('{0} {0,number}')); +?> +--EXPECT-- +string(13) "Hello, world!" +bool(false) +string(11) "Hello, {0}!" +string(13) "Hello, world!" +bool(true) +string(7) "2 items" +bool(true)

« previous php.cvs (#144136) next »