php-src icon indicating copy to clipboard operation
php-src copied to clipboard

msgfmt_format $values may not support references

Open hhofstaetter opened this issue 4 years ago • 1 comments

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

hhofstaetter avatar Apr 13 '22 14:04 hhofstaetter

Yeah, we're missing the handling of references (IS_REFERENCE) here.

cmb69 avatar Apr 13 '22 14:04 cmb69