File tree Expand file tree Collapse file tree 2 files changed +33
-15
lines changed Expand file tree Collapse file tree 2 files changed +33
-15
lines changed Original file line number Diff line number Diff line change @@ -48,23 +48,23 @@ PHP_FUNCTION( numfmt_format )
48
48
/* Fetch the object. */
49
49
FORMATTER_METHOD_FETCH_OBJECT ;
50
50
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 );
64
55
}
65
56
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
+ }
68
68
}
69
69
70
70
switch (type ) {
Original file line number Diff line number Diff line change
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"
You can’t perform that action at this time.
0 commit comments