Skip to content

Commit 9285823

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

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
@@ -6,6 +6,8 @@ PHP NEWS
66
. Fix incorrect argument positions for uninitialized calendar arguments in
77
IntlCalendar::equals(), ::before(), ::after(), and ::isEquivalentTo().
88
(Weilin Du)
9+
. Fixed MessageFormatter::parse() and parseMessage() returning PHP_INT_MIN
10+
as float rather than int on 64-bit platforms. (Weilin Du)
911

1012
- Zlib:
1113
. Fixed memory leak if deflate initialization fails and there is a dict.

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,8 @@ PHP 8.4 UPGRADE NOTES
10151015
. The behaviour of Intl class has been normalized to always throw Error
10161016
exceptions when attempting to use a non-initialized object,
10171017
or when cloning fails.
1018+
. MessageFormatter::parse() and parseMessage() now return PHP_INT_MIN as
1019+
int, rather than float, on 64-bit platforms when parsing integer values.
10181020

10191021
- LibXML:
10201022
. The libxml extension now requires at least libxml2 2.9.4.

ext/intl/msgformat/msgformat_helpers.cpp

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

654654
case Formattable::kInt64:
655655
aInt64 = fargs[i].getInt64();
656-
if(aInt64 > ZEND_LONG_MAX || aInt64 < -ZEND_LONG_MAX) {
656+
if(aInt64 > ZEND_LONG_MAX || aInt64 < ZEND_LONG_MIN) {
657657
ZVAL_DOUBLE(&(*args)[i], (double)aInt64);
658658
} else {
659659
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)