Skip to content

Commit 71e198b

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
2 parents 3d5df06 + 47500f3 commit 71e198b

File tree

4 files changed

+91
-3
lines changed

4 files changed

+91
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ PHP NEWS
2424
. Fixed bug GH-9308 (GMP throws the wrong error when a GMP object is passed
2525
to gmp_init()). (Girgias)
2626

27+
- Intl
28+
. Fixed bug GH-9421 (Incorrect argument number for ValueError in NumberFormatter).
29+
(Girgias)
30+
2731
- PCRE:
2832
. Fixed pcre.jit on Apple Silicon. (Niklas Keller)
2933

ext/intl/formatter/formatter_format.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,18 @@ PHP_FUNCTION( numfmt_format )
103103
}
104104
INTL_METHOD_CHECK_STATUS( nfo, "Number formatting failed" );
105105
break;
106-
106+
case FORMAT_TYPE_CURRENCY:
107+
if (getThis()) {
108+
const char *space;
109+
const char *class_name = get_active_class_name(&space);
110+
zend_argument_value_error(2, "cannot be NumberFormatter::TYPE_CURRENCY constant, "
111+
"use %s%sformatCurrency() method instead", class_name, space);
112+
} else {
113+
zend_argument_value_error(3, "cannot be NumberFormatter::TYPE_CURRENCY constant, use numfmt_format_currency() function instead");
114+
}
115+
RETURN_THROWS();
107116
default:
108-
zend_argument_value_error(3, "must be a NumberFormatter::TYPE_* constant");
117+
zend_argument_value_error(getThis() ? 2 : 3, "must be a NumberFormatter::TYPE_* constant");
109118
RETURN_THROWS();
110119
}
111120

ext/intl/formatter/formatter_parse.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,18 @@ PHP_FUNCTION( numfmt_parse )
8585
val_double = unum_parseDouble(FORMATTER_OBJECT(nfo), sstr, sstr_len, position_p, &INTL_DATA_ERROR_CODE(nfo));
8686
RETVAL_DOUBLE(val_double);
8787
break;
88+
case FORMAT_TYPE_CURRENCY:
89+
if (getThis()) {
90+
const char *space;
91+
const char *class_name = get_active_class_name(&space);
92+
zend_argument_value_error(2, "cannot be NumberFormatter::TYPE_CURRENCY constant, "
93+
"use %s%sparseCurrency() method instead", class_name, space);
94+
} else {
95+
zend_argument_value_error(3, "cannot be NumberFormatter::TYPE_CURRENCY constant, use numfmt_parse_currency() function instead");
96+
}
97+
goto cleanup;
8898
default:
89-
zend_argument_value_error(3, "must be a NumberFormatter::TYPE_* constant");
99+
zend_argument_value_error(getThis() ? 2 : 3, "must be a NumberFormatter::TYPE_* constant");
90100
goto cleanup;
91101
}
92102

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
--TEST--
2+
ValueErrors for format/parse methods and procedural functions
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
8+
$o = new NumberFormatter('en_US', NumberFormatter::PATTERN_DECIMAL);
9+
$num = 5;
10+
$str = "string";
11+
12+
/* Unknown type constant */
13+
try {
14+
numfmt_format($o, $num, -20);
15+
} catch (\ValueError $e) {
16+
echo $e->getMessage(), \PHP_EOL;
17+
}
18+
try {
19+
$o->format($num, -20);
20+
} catch (\ValueError $e) {
21+
echo $e->getMessage(), \PHP_EOL;
22+
}
23+
try {
24+
numfmt_parse($o, $str, -20);
25+
} catch (\ValueError $e) {
26+
echo $e->getMessage(), \PHP_EOL;
27+
}
28+
try {
29+
$o->parse($str, -20);
30+
} catch (\ValueError $e) {
31+
echo $e->getMessage(), \PHP_EOL;
32+
}
33+
34+
/* With NumberFormatter::TYPE_CURRENCY */
35+
try {
36+
numfmt_format($o, $num, NumberFormatter::TYPE_CURRENCY);
37+
} catch (\ValueError $e) {
38+
echo $e->getMessage(), \PHP_EOL;
39+
}
40+
try {
41+
$o->format($num, NumberFormatter::TYPE_CURRENCY);
42+
} catch (\ValueError $e) {
43+
echo $e->getMessage(), \PHP_EOL;
44+
}
45+
try {
46+
numfmt_parse($o, $str, NumberFormatter::TYPE_CURRENCY);
47+
} catch (\ValueError $e) {
48+
echo $e->getMessage(), \PHP_EOL;
49+
}
50+
try {
51+
$o->parse($str, NumberFormatter::TYPE_CURRENCY);
52+
} catch (\ValueError $e) {
53+
echo $e->getMessage(), \PHP_EOL;
54+
}
55+
56+
?>
57+
--EXPECT--
58+
numfmt_format(): Argument #3 ($type) must be a NumberFormatter::TYPE_* constant
59+
NumberFormatter::format(): Argument #2 ($type) must be a NumberFormatter::TYPE_* constant
60+
numfmt_parse(): Argument #3 ($type) must be a NumberFormatter::TYPE_* constant
61+
NumberFormatter::parse(): Argument #2 ($type) must be a NumberFormatter::TYPE_* constant
62+
numfmt_format(): Argument #3 ($type) cannot be NumberFormatter::TYPE_CURRENCY constant, use numfmt_format_currency() function instead
63+
NumberFormatter::format(): Argument #2 ($type) cannot be NumberFormatter::TYPE_CURRENCY constant, use NumberFormatter::formatCurrency() method instead
64+
numfmt_parse(): Argument #3 ($type) cannot be NumberFormatter::TYPE_CURRENCY constant, use numfmt_parse_currency() function instead
65+
NumberFormatter::parse(): Argument #2 ($type) cannot be NumberFormatter::TYPE_CURRENCY constant, use NumberFormatter::parseCurrency() method instead

0 commit comments

Comments
 (0)