Skip to content

Commit e3cac07

Browse files
committed
Fix numfmt_parse_currency() reference handling
Closes phpGH-18472.
1 parent d9d58c9 commit e3cac07

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

ext/intl/formatter/formatter_parse.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ PHP_FUNCTION( numfmt_parse_currency )
135135
FORMATTER_METHOD_INIT_VARS;
136136

137137
/* Parse parameters. */
138-
if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Osz/|z!",
138+
if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Osz|z!",
139139
&object, NumberFormatter_ce_ptr, &str, &str_len, &zcurrency, &zposition ) == FAILURE )
140140
{
141141
RETURN_THROWS();
@@ -165,8 +165,7 @@ PHP_FUNCTION( numfmt_parse_currency )
165165
/* Convert parsed currency to UTF-8 and pass it back to caller. */
166166
u8str = intl_convert_utf16_to_utf8(currency, u_strlen(currency), &INTL_DATA_ERROR_CODE(nfo));
167167
INTL_METHOD_CHECK_STATUS( nfo, "Currency conversion to UTF-8 failed" );
168-
zval_ptr_dtor( zcurrency );
169-
ZVAL_NEW_STR(zcurrency, u8str);
168+
ZEND_TRY_ASSIGN_REF_NEW_STR(zcurrency, u8str);
170169

171170
RETVAL_DOUBLE( number );
172171
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
numfmt_parse_currency() reference handling
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
class Test {
8+
public int $prop = 1;
9+
}
10+
$test = new Test;
11+
$fmt = numfmt_create( 'de_DE', NumberFormatter::CURRENCY );
12+
$num = "1\xc2\xa0$";
13+
try {
14+
numfmt_parse_currency($fmt, $num, $test->prop);
15+
} catch (TypeError $e) {
16+
echo $e->getMessage(), "\n";
17+
}
18+
?>
19+
--EXPECT--
20+
Cannot assign string to reference held by property Test::$prop of type int

0 commit comments

Comments
 (0)