Skip to content
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

msgfmt_format $values may not support references #8364

Closed
hhofstaetter opened this issue Apr 13, 2022 · 1 comment
Closed

msgfmt_format $values may not support references #8364

hhofstaetter opened this issue Apr 13, 2022 · 1 comment

Comments

@hhofstaetter
Copy link

hhofstaetter commented Apr 13, 2022

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

@cmb69
Copy link
Member

cmb69 commented Apr 13, 2022

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

@cmb69 cmb69 changed the title MessageFormatter fails with U_ILLEGAL_ARGUMENT_ERROR msgfmt_format $values may not support references Apr 20, 2022
@cmb69 cmb69 self-assigned this Apr 20, 2022
cmb69 added a commit to cmb69/php-src that referenced this issue Apr 20, 2022
We need to deref any references passed in the `$values` array.  While
we could handle this in the type switch, doing it right away in the
foreach loop makes that more explicit, and also circumvents the missing
range checks for integers which are not passed as int or double.
@cmb69 cmb69 linked a pull request Apr 20, 2022 that will close this issue
cmb69 added a commit that referenced this issue Apr 24, 2022
* PHP-8.0:
  Fix GH-8364: msgfmt_format $values may not support references
@cmb69 cmb69 closed this as completed in f5d9e7c Apr 24, 2022
cmb69 added a commit that referenced this issue Apr 24, 2022
* PHP-8.1:
  Fix GH-8364: msgfmt_format $values may not support references
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@cmb69 @hhofstaetter and others