Commit a4ff76ec1a2 for php.net
commit a4ff76ec1a255fcb21fcacd333629f212c16b723
Author: “LamentXU123” <108666168+LamentXU123@users.noreply.github.com>
Date: Mon Jun 1 23:45:29 2026 +0800
ext/intl: Preserve int64 precision in IntlNumberRangeFormatter::format()
diff --git a/ext/intl/rangeformatter/rangeformatter_class.cpp b/ext/intl/rangeformatter/rangeformatter_class.cpp
index 6921791e588..2df252d1986 100644
--- a/ext/intl/rangeformatter/rangeformatter_class.cpp
+++ b/ext/intl/rangeformatter/rangeformatter_class.cpp
@@ -60,6 +60,19 @@ zend_object *IntlNumberRangeFormatter_object_create(zend_class_entry *ce)
return &intern->zo;
}
+static icu::Formattable rangeformatter_create_formattable(zval *number)
+{
+ icu::Formattable formattable;
+
+ if (Z_TYPE_P(number) == IS_DOUBLE) {
+ formattable.setDouble(Z_DVAL_P(number));
+ } else {
+ formattable.setInt64(static_cast<int64_t>(Z_LVAL_P(number)));
+ }
+
+ return formattable;
+}
+
U_CFUNC PHP_METHOD(IntlNumberRangeFormatter, __construct)
{
ZEND_PARSE_PARAMETERS_NONE();
@@ -154,8 +167,8 @@ U_CFUNC PHP_METHOD(IntlNumberRangeFormatter, format)
UErrorCode error = U_ZERO_ERROR;
- icu::Formattable start_formattable(Z_TYPE_P(start) == IS_DOUBLE ? Z_DVAL_P(start) : Z_LVAL_P(start));
- icu::Formattable end_formattable(Z_TYPE_P(end) == IS_DOUBLE ? Z_DVAL_P(end) : Z_LVAL_P(end));
+ icu::Formattable start_formattable = rangeformatter_create_formattable(start);
+ icu::Formattable end_formattable = rangeformatter_create_formattable(end);
UnicodeString result = RANGEFORMATTER_OBJECT(obj)->formatFormattableRange(start_formattable, end_formattable, error).toString(error);
diff --git a/ext/intl/tests/rangeformatter/rangeformatter_format_int64.phpt b/ext/intl/tests/rangeformatter/rangeformatter_format_int64.phpt
new file mode 100644
index 00000000000..9cefbcfb1ea
--- /dev/null
+++ b/ext/intl/tests/rangeformatter/rangeformatter_format_int64.phpt
@@ -0,0 +1,27 @@
+--TEST--
+IntlNumberRangeFormatter::format() preserves int64 precision
+--EXTENSIONS--
+intl
+--SKIPIF--
+<?php
+if (!class_exists('IntlNumberRangeFormatter')) {
+ die('skip IntlNumberRangeFormatter not available');
+}
+if (PHP_INT_SIZE < 8) {
+ die('skip 64-bit only');
+}
+?>
+--FILE--
+<?php
+$formatter = IntlNumberRangeFormatter::createFromSkeleton(
+ '',
+ 'en_US',
+ IntlNumberRangeFormatter::COLLAPSE_AUTO,
+ IntlNumberRangeFormatter::IDENTITY_FALLBACK_SINGLE_VALUE
+);
+
+$formatted = $formatter->format(9007199254740993, 9007199254740993);
+var_dump(preg_replace('/[^0-9]/', '', $formatted));
+?>
+--EXPECT--
+string(16) "9007199254740993"