Skip to content

Commit 45074ee

Browse files
committed
ext/Intl: Return PHP_INT_MIN as int from MessageFormatter::parse() on 64-bit
1 parent e22ba55 commit 45074ee

4 files changed

Lines changed: 31 additions & 1 deletion

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ PHP NEWS
6969
argument handling now raises TypeError instead of Error. (Weilin Du)
7070
. IntlBreakIterator::getLocale() now raises ValueError for invalid locale
7171
types. (Weilin Du)
72+
. Fixed MessageFormatter::parse() and parseMessage() returning PHP_INT_MIN
73+
as float rather than int on 64-bit platforms. (Weilin Du)
7274

7375
- JSON:
7476
. Enriched JSON last error / exception message with error location.

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ PHP 8.6 UPGRADE NOTES
4040
. IntlBreakIterator::getLocale() now raises a ValueError when the type is
4141
neither Locale::ACTUAL_LOCALE nor Locale::VALID_LOCALE instead of
4242
returning false.
43+
. MessageFormatter::parse() and parseMessage() now return PHP_INT_MIN as
44+
int, rather than float, on 64-bit platforms when parsing integer values.
4345

4446
- PCNTL:
4547
. pcntl_alarm() now raises a ValueError if the seconds argument is

ext/intl/msgformat/msgformat_helpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ U_CFUNC void umsg_parse_helper(UMessageFormat *fmt, int *count, zval **args, UCh
649649

650650
case Formattable::kInt64:
651651
aInt64 = fargs[i].getInt64();
652-
if(aInt64 > ZEND_LONG_MAX || aInt64 < -ZEND_LONG_MAX) {
652+
if(aInt64 > ZEND_LONG_MAX || aInt64 < ZEND_LONG_MIN) {
653653
ZVAL_DOUBLE(&(*args)[i], (double)aInt64);
654654
} else {
655655
ZVAL_LONG(&(*args)[i], (zend_long)aInt64);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug: MessageFormatter::parse() should preserve PHP_INT_MIN as int on 64-bit
3+
--EXTENSIONS--
4+
intl
5+
--SKIPIF--
6+
<?php if (PHP_INT_SIZE != 8) die("skip 64-bit only"); ?>
7+
--FILE--
8+
<?php
9+
10+
$fmt = new MessageFormatter('en_US', '{0,number,integer}');
11+
$parsed = $fmt->parse('-9,223,372,036,854,775,808');
12+
var_dump($parsed);
13+
14+
$parsed = MessageFormatter::parseMessage('en_US', '{0,number,integer}', '-9,223,372,036,854,775,808');
15+
var_dump($parsed);
16+
17+
?>
18+
--EXPECT--
19+
array(1) {
20+
[0]=>
21+
int(-9223372036854775808)
22+
}
23+
array(1) {
24+
[0]=>
25+
int(-9223372036854775808)
26+
}

0 commit comments

Comments
 (0)