}
break;
+ case 'n':
+ {
+ zval **p = va_arg(*va, zval **);
+
+ if (!zend_parse_arg_number(arg, p, check_null)) {
+ return "number";
+ }
+ }
+ break;
+
case 's':
{
char **p = va_arg(*va, char **);
case 'f': case 'A':
case 'H': case 'p':
case 'S': case 'P':
- case 'L':
+ case 'L': case 'n':
max_num_args++;
break;
#define Z_PARAM_LONG_OR_NULL(dest, is_null) \
Z_PARAM_LONG_EX(dest, is_null, 1, 0)
-/* no old equivalent */
+/* old "n" */
#define Z_PARAM_NUMBER_EX(dest, check_null) \
Z_PARAM_PROLOGUE(0, 0); \
if (UNEXPECTED(!zend_parse_arg_number(_arg, &dest, check_null))) { \
h - array (returned as HashTable*)
H - array or HASH_OF(object) (returned as HashTable*)
l - long (zend_long)
+n - long or double (zval*)
o - object of any type (zval*)
O - object of specific type given by class entry (zval*, zend_class_entry)
p - valid path (string without null bytes in the middle) and its length (char*, size_t)
public static function create(string $locale, int $style, string $pattern = "") {}
/** @return string|false */
- public function format($value, int $type = NumberFormatter::TYPE_DEFAULT) {}
+ public function format(int|float $value, int $type = NumberFormatter::TYPE_DEFAULT) {}
/** @return int|float|false */
public function parse(string $value, int $type = NumberFormatter::TYPE_DOUBLE, &$position = null) {}
function numfmt_create(string $locale, int $style, string $pattern = ""): ?NumberFormatter {}
-function numfmt_format(NumberFormatter $fmt, $value, int $type = NumberFormatter::TYPE_DEFAULT): string|false {}
+function numfmt_format(NumberFormatter $fmt, int|float $value, int $type = NumberFormatter::TYPE_DEFAULT): string|false {}
function numfmt_parse(NumberFormatter $fmt, string $value, int $type = NumberFormatter::TYPE_DOUBLE, &$position = null): int|float|false {}
#define arginfo_class_NumberFormatter_create arginfo_class_NumberFormatter___construct
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_NumberFormatter_format, 0, 0, 1)
- ZEND_ARG_INFO(0, value)
+ ZEND_ARG_TYPE_MASK(0, value, MAY_BE_LONG|MAY_BE_DOUBLE)
ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_numfmt_format, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, fmt, NumberFormatter, 0)
- ZEND_ARG_INFO(0, value)
+ ZEND_ARG_TYPE_MASK(0, value, MAY_BE_LONG|MAY_BE_DOUBLE)
ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0)
ZEND_END_ARG_INFO()
FORMATTER_METHOD_INIT_VARS;
/* Parse parameters. */
- if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Oz|l",
+ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "On|l",
&object, NumberFormatter_ce_ptr, &number, &type ) == FAILURE )
{
RETURN_THROWS();
/* Fetch the object. */
FORMATTER_METHOD_FETCH_OBJECT;
- if(Z_TYPE_P(number) != IS_ARRAY) {
- convert_scalar_to_number_ex(number);
- } else {
- convert_to_long(number);
- }
-
if(type == FORMAT_TYPE_DEFAULT) {
switch(Z_TYPE_P(number)) {
case IS_LONG:
<?php
$x = new NumberFormatter('en_US', NumberFormatter::DECIMAL);
-var_dump($x->format(''));
-var_dump($x->format(1));
-var_dump($x->format(NULL));
-var_dump($x->format($x));
+foreach (['', 1, NULL, $x] as $value) {
+ try {
+ var_dump($x->format($value));
+ } catch (TypeError $ex) {
+ echo $ex->getMessage(), PHP_EOL;
+ }
+}
?>
---EXPECTF--
-string(1) "0"
+--EXPECT--
+NumberFormatter::format() expects parameter 1 to be number, string given
string(1) "1"
string(1) "0"
-
-Notice: Object of class NumberFormatter could not be converted to number in %s on line %d
-string(1) "1"
+NumberFormatter::format() expects parameter 1 to be number, object given
--EXPECTF--
string(%d) "5,50 kr%A"
string(%d) "5,50 kr%A"
+
+Notice: A non well formed numeric value encountered in %s on line %d
string(%d) "5,00 kr%A"
string(5) "23,25"
string(3) "26%"
+++ /dev/null
---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));
-?>
---EXPECTF--
-string(21) "823749273428379%c%c%c%c%c%c"
-string(1) "1"