[php-src] PHP-8.5: ext/intl: Reset IntlListFormatter error state in constructor (#22931)
Weilin Du via GitHub <[email protected]> Sat, 1 Aug 2026 16:07:28 +0000
| Newsgroups | gmane.comp.php.cvs.general |
|---|---|
| Message-ID | <[email protected]> |
Author: Weilin Du (LamentXU123)
Committer: GitHub (web-flow)
Pusher: LamentXU123
Date: 2026-08-02T00:07:26+08:00
Commit: https://github.com/php/php-src/commit/94d00c932738af7f61da072a88503d6344e57867
Raw diff: https://github.com/php/php-src/commit/94d00c932738af7f61da072a88503d6344e57867.diff
ext/intl: Reset IntlListFormatter error state in constructor (#22931)
Fixed IntlListFormatter::__construct() leaving stale global error state after
successful calls.
Changed paths:
A ext/intl/tests/listformatter/listformatter_constructor_error_reset.phpt
M NEWS
M ext/intl/listformatter/listformatter_class.c
Diff:
diff --git a/NEWS b/NEWS
index 77c650ec5a9e..78d561c25986 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,10 @@ PHP NEWS
. Fixed bug GH-22825 (DOMElement::setAttribute() fails silently when the DTD
declares a default value for the attribute). (iliaal)
+- Intl:
+ . Fixed IntlListFormatter::__construct() leaving stale global error state
+ after successful calls. (Weilin Du)
+
- Opcache:
. Fixed GH-22693 (DT_TEXTREL in JIT-generated TLS access on x86_64).
(David Carlier)
diff --git a/ext/intl/listformatter/listformatter_class.c b/ext/intl/listformatter/listformatter_class.c
index d8c9c792e036..c8d835170c5c 100644
--- a/ext/intl/listformatter/listformatter_class.c
+++ b/ext/intl/listformatter/listformatter_class.c
@@ -60,6 +60,9 @@ PHP_METHOD(IntlListFormatter, __construct)
zend_long type = INTL_LISTFORMATTER_FALLBACK_TYPE_AND;
zend_long width = INTL_LISTFORMATTER_FALLBACK_WIDTH_WIDE;
#endif
+
+ intl_errors_reset(LISTFORMATTER_ERROR_P(obj));
+
ZEND_PARSE_PARAMETERS_START(1, 3)
Z_PARAM_STRING(locale, locale_len)
Z_PARAM_OPTIONAL
diff --git a/ext/intl/tests/listformatter/listformatter_constructor_error_reset.phpt b/ext/intl/tests/listformatter/listformatter_constructor_error_reset.phpt
new file mode 100644
index 000000000000..3360bb848fa6
--- /dev/null
+++ b/ext/intl/tests/listformatter/listformatter_constructor_error_reset.phpt
@@ -0,0 +1,23 @@
+--TEST--
+IntlListFormatter::__construct() resets stale errors
+--EXTENSIONS--
+intl
+--FILE--
+<?php
+$formatter = new IntlListFormatter('en_US');
+var_dump($formatter->format(["\x80"]));
+var_dump(intl_get_error_code() === U_INVALID_CHAR_FOUND);
+
+$formatter = new IntlListFormatter('en_US');
+var_dump(intl_get_error_code());
+var_dump(intl_get_error_message());
+var_dump($formatter->getErrorCode());
+var_dump($formatter->getErrorMessage());
+?>
+--EXPECT--
+bool(false)
+bool(true)
+int(0)
+string(12) "U_ZERO_ERROR"
+int(0)
+string(12) "U_ZERO_ERROR"