Skip to content

Commit 6b55425

Browse files
committed
Prevent double-construction of NumberFormatter
1 parent 72eaf50 commit 6b55425

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

ext/intl/formatter/formatter_main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
4343
INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len);
4444
object = return_value;
4545
FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK;
46+
if (FORMATTER_OBJECT(nfo)) {
47+
zend_throw_error(NULL, "NumberFormatter object is already constructed");
48+
return FAILURE;
49+
}
4650

4751
/* Convert pattern (if specified) to UTF-16. */
4852
if(pattern && pattern_len) {

ext/intl/tests/formatter_fail.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ try {
7575
}
7676
err($fmt);
7777

78+
$fmt = new NumberFormatter('en_US', NumberFormatter::DECIMAL);
79+
try {
80+
$fmt->__construct('en_US', NumberFormatter::DECIMAL);
81+
} catch (Error $e) {
82+
print_exception($e);
83+
$fmt = null;
84+
}
85+
err($fmt);
86+
7887
foreach($args as $arg) {
7988
$fmt = crt("O", $arg[0], $arg[1]);
8089
err($fmt);
@@ -95,6 +104,9 @@ ArgumentCountError: numfmt_create() expects at least 2 parameters, 0 given in %s
95104
ArgumentCountError: NumberFormatter::create() expects at least 2 parameters, 0 given in %s on line %d
96105
'U_ZERO_ERROR'
97106

107+
Error: NumberFormatter object is already constructed in %s on line %d
108+
'U_ZERO_ERROR'
109+
98110
IntlException: Constructor failed in %s on line %d
99111
'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
100112
'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'

0 commit comments

Comments
 (0)