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

From: Date: Tue, 24 Nov 2026 20:55:10 +0000
Subject: [php-src] master: Merge branch 'PHP-8.6'
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-144137@lists.php.net to get a copy of this message
Author: Weilin Du (LamentXU123) Date: 2026-11-25T04:53:37+08:00 Commit: https://github.com/php/php-src/commit/d9d14dbc4009b9c3a4b2073939d325808f39f9aa Raw diff: https://github.com/php/php-src/commit/d9d14dbc4009b9c3a4b2073939d325808f39f9aa.diff Merge branch 'PHP-8.6' * PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6 Changed paths: A ext/intl/tests/msgfmt_set_pattern_preserves_state.phpt M ext/intl/msgformat/msgformat_attr.cpp Diff: diff --git a/ext/intl/msgformat/msgformat_attr.cpp b/ext/intl/msgformat/msgformat_attr.cpp index bb7b21640158..c6614c6d1365 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> + #include "php_intl.h" #include "msgformat_class.h" #include "msgformat_data.h" @@ -76,7 +80,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); } @@ -88,6 +98,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 (#144137) next »