Skip to content

Commit aba6937

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #79212: NumberFormatter::format() may detect wrong type
2 parents c2a61c9 + 57b9eca commit aba6937

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

ext/intl/formatter/formatter_format.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,23 @@ PHP_FUNCTION( numfmt_format )
4848
/* Fetch the object. */
4949
FORMATTER_METHOD_FETCH_OBJECT;
5050

51-
if(type == FORMAT_TYPE_DEFAULT) {
52-
if(Z_TYPE_P(number) == IS_STRING) {
53-
convert_scalar_to_number_ex(number);
54-
}
55-
56-
if(Z_TYPE_P(number) == IS_LONG) {
57-
/* take INT32 on 32-bit, int64 on 64-bit */
58-
type = (sizeof(zend_long) == 8)?FORMAT_TYPE_INT64:FORMAT_TYPE_INT32;
59-
} else if(Z_TYPE_P(number) == IS_DOUBLE) {
60-
type = FORMAT_TYPE_DOUBLE;
61-
} else {
62-
type = FORMAT_TYPE_INT32;
63-
}
51+
if(Z_TYPE_P(number) != IS_ARRAY) {
52+
convert_scalar_to_number_ex(number);
53+
} else {
54+
convert_to_long(number);
6455
}
6556

66-
if(Z_TYPE_P(number) != IS_DOUBLE && Z_TYPE_P(number) != IS_LONG) {
67-
convert_scalar_to_number(number );
57+
if(type == FORMAT_TYPE_DEFAULT) {
58+
switch(Z_TYPE_P(number)) {
59+
case IS_LONG:
60+
/* take INT32 on 32-bit, int64 on 64-bit */
61+
type = (sizeof(zend_long) == 8)?FORMAT_TYPE_INT64:FORMAT_TYPE_INT32;
62+
break;
63+
case IS_DOUBLE:
64+
type = FORMAT_TYPE_DOUBLE;
65+
break;
66+
EMPTY_SWITCH_DEFAULT_CASE();
67+
}
6868
}
6969

7070
switch(type) {

ext/intl/tests/bug79212.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #79212 (NumberFormatter::format() may detect wrong type)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('intl')) die('skip intl extension not available');
6+
if (!extension_loaded('gmp')) die('skip gmp extension not available');
7+
?>
8+
--FILE--
9+
<?php
10+
$fmt = new NumberFormatter('en_US', NumberFormatter::PATTERN_DECIMAL);
11+
var_dump($fmt->format(gmp_init('823749273428379492374')));
12+
13+
$fmt = new NumberFormatter('en_US', NumberFormatter::PATTERN_DECIMAL);
14+
var_dump($fmt->format([1], NumberFormatter::TYPE_INT64));
15+
?>
16+
--EXPECT--
17+
string(21) "823749273428379400000"
18+
string(1) "1"

0 commit comments

Comments
 (0)