Skip to content

Disallow passing array as number to NumberFormatter::format() #5181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ext/intl/formatter/formatter_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ PHP_FUNCTION( numfmt_format )
{
RETURN_THROWS();
}
if(Z_TYPE_P(number) == IS_ARRAY) {
zend_type_error("given value must not be an array");
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);
}
convert_scalar_to_number_ex(number);

if(type == FORMAT_TYPE_DEFAULT) {
switch(Z_TYPE_P(number)) {
Expand Down
7 changes: 6 additions & 1 deletion ext/intl/tests/bug79212.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ var_dump($fmt->format([1], NumberFormatter::TYPE_INT64));
?>
--EXPECTF--
string(21) "823749273428379%c%c%c%c%c%c"
string(1) "1"

Fatal error: Uncaught TypeError: given value must not be an array in %s:%d
Stack trace:
#0 %s(%d): NumberFormatter->format(Array, 2)
#1 {main}
thrown in %s on line %d