Skip to content

msgfmt_format $values may not support references #8364

Closed

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

Activity

  1. cmb69 commented on Apr 13, 2022

    @cmb69
    Member

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

  2. changed the title [-]MessageFormatter fails with U_ILLEGAL_ARGUMENT_ERROR[/-] [+]msgfmt_format $values may not support references[/+] on Apr 20, 2022
  3. self-assigned this
    on Apr 20, 2022
  4. added a commit that references this issue on Apr 20, 2022
    f8c2273
  5. added 2 commits that reference this issue on Apr 24, 2022
    f5d9e7c
    1c0dc2a
  6. added a commit that references this issue on Apr 24, 2022
    19273ff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions