Skip to content

msgfmt_format $values may not support references #8364

Closed
@hhofstaetter

Description

@hhofstaetter

Description

The following code:

<?php
$formatter = new MessageFormatter('en', 'translate {0}');
$args = ['string', 'string'];
foreach ($args as &$arg) {
//     do nothing;
}
$result = $formatter->format($args);
var_dump($result);
var_dump(intl_get_error_message());

Resulted in this output:

bool(false)
string(107) "No strategy to convert the value given for the argument with key '1' is available: U_ILLEGAL_ARGUMENT_ERROR"

But I expected this output instead:

string(11) "translate string"
string(12) "U_ZERO_ERROR"

The error happens only if arguments are used in the foreach by reference and only if the number of arguments in the array and in the translation string are different.
The code works fine in 5.6, it fails in 7.0 and newer versions.

PHP Version

8.0.17, 8.1.4

Operating System

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions