mirror of
https://github.com/php/php-src.git
synced 2024-12-18 22:41:20 +08:00
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #79212: NumberFormatter::format() may detect wrong type
This commit is contained in:
commit
aba6937c0a
@ -48,25 +48,25 @@ PHP_FUNCTION( numfmt_format )
|
|||||||
/* Fetch the object. */
|
/* Fetch the object. */
|
||||||
FORMATTER_METHOD_FETCH_OBJECT;
|
FORMATTER_METHOD_FETCH_OBJECT;
|
||||||
|
|
||||||
if(type == FORMAT_TYPE_DEFAULT) {
|
if(Z_TYPE_P(number) != IS_ARRAY) {
|
||||||
if(Z_TYPE_P(number) == IS_STRING) {
|
|
||||||
convert_scalar_to_number_ex(number);
|
convert_scalar_to_number_ex(number);
|
||||||
|
} else {
|
||||||
|
convert_to_long(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Z_TYPE_P(number) == IS_LONG) {
|
if(type == FORMAT_TYPE_DEFAULT) {
|
||||||
|
switch(Z_TYPE_P(number)) {
|
||||||
|
case IS_LONG:
|
||||||
/* take INT32 on 32-bit, int64 on 64-bit */
|
/* take INT32 on 32-bit, int64 on 64-bit */
|
||||||
type = (sizeof(zend_long) == 8)?FORMAT_TYPE_INT64:FORMAT_TYPE_INT32;
|
type = (sizeof(zend_long) == 8)?FORMAT_TYPE_INT64:FORMAT_TYPE_INT32;
|
||||||
} else if(Z_TYPE_P(number) == IS_DOUBLE) {
|
break;
|
||||||
|
case IS_DOUBLE:
|
||||||
type = FORMAT_TYPE_DOUBLE;
|
type = FORMAT_TYPE_DOUBLE;
|
||||||
} else {
|
break;
|
||||||
type = FORMAT_TYPE_INT32;
|
EMPTY_SWITCH_DEFAULT_CASE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Z_TYPE_P(number) != IS_DOUBLE && Z_TYPE_P(number) != IS_LONG) {
|
|
||||||
convert_scalar_to_number(number );
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case FORMAT_TYPE_INT32:
|
case FORMAT_TYPE_INT32:
|
||||||
convert_to_long_ex(number);
|
convert_to_long_ex(number);
|
||||||
|
18
ext/intl/tests/bug79212.phpt
Normal file
18
ext/intl/tests/bug79212.phpt
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
--TEST--
|
||||||
|
Bug #79212 (NumberFormatter::format() may detect wrong type)
|
||||||
|
--SKIPIF--
|
||||||
|
<?php
|
||||||
|
if (!extension_loaded('intl')) die('skip intl extension not available');
|
||||||
|
if (!extension_loaded('gmp')) die('skip gmp extension not available');
|
||||||
|
?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$fmt = new NumberFormatter('en_US', NumberFormatter::PATTERN_DECIMAL);
|
||||||
|
var_dump($fmt->format(gmp_init('823749273428379492374')));
|
||||||
|
|
||||||
|
$fmt = new NumberFormatter('en_US', NumberFormatter::PATTERN_DECIMAL);
|
||||||
|
var_dump($fmt->format([1], NumberFormatter::TYPE_INT64));
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
string(21) "823749273428379400000"
|
||||||
|
string(1) "1"
|
Loading…
Reference in New Issue
Block a user