php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62673 Reusing tokens in MessageFormatter causes it to return NULL
Submitted: 2012-07-27 11:06 UTC Modified: 2012-07-27 15:14 UTC
From: abxccd at msn dot com Assigned:
Status: Not a bug Package: intl (PECL)
PHP Version: 5.3.15 OS: Windows 7 64-bit
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: abxccd at msn dot com
New email:
PHP Version: OS:

 

 [2012-07-27 11:06 UTC] abxccd at msn dot com
Description:
------------
I am using PHP 5.3.15 VC9 NTS on a Windows 7 64-bit machine. PHP is running as a fcgid on Apache 2.4.2. ICU is 49.1.2

If we repeat tokens and use it with a SelectFormat when using the MessageFormatter, it fails and returns NULL.

For example, one such pattern would be:
{0}{0, plural, one{minute ago} other{minutes}}

This has worked well previously, but upon upgrading to 3.0.0a2, it has failed when processing that pattern.

Test script:
---------------
$fmt = new MessageFormatter("en", "{1}{0, plural, one{minute ago} other{minutes}}");
var_dump($fmt); //Works
echo $fmt->format(array(2, 2));

$fmt2 = new MessageFormatter("en", "{0}{0, plural, one{minute} other{minutes}}");
var_dump($fmt2); //NULL
echo $fmt2->format(array(2));



Expected result:
----------------
The message formatter ($fmt2) should return a valid MessageFormatter object to allow further interactions.

Actual result:
--------------
$fmt2 returns a NULL.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-27 15:14 UTC] cataphract@php.net
The change, if any, occurred in ICU. The behavior you describe is simply ICU's behavior, as this C program shows:

#include <unicode/umsg.h>
#include <unicode/ustring.h>
#include <stdio.h>
#include <string.h>

#define PATTERN "{0}{0, plural, one{minute} other{minutes}}"
#define PATTERN2 "{0, number}{0, plural, one{minute} other{minutes}}"

int main()
{
	UChar pattern[1024];
	UErrorCode uec = 0;
	u_uastrcpy(pattern, PATTERN);
	umsg_open(pattern, strlen(PATTERN), "en", NULL, &uec);
	printf("%d (%s)\n", uec, u_errorName(uec));

	uec = 0;
	u_uastrcpy(pattern, PATTERN2);
	umsg_open(pattern, strlen(PATTERN2), "en", NULL, &uec);
	printf("%d (%s)\n", uec, u_errorName(uec));

	return 0;
}

Output:

65804 (U_ARGUMENT_TYPE_MISMATCH)
0 (U_ZERO_ERROR)

The work around to avoid the type mismatch error is to force the same instance of the placeholder to have the same type as the second one (which is of type double, because it's a plural placeholder). So:

"{0, number}{0, plural, one{minute} other{minutes}}"
 [2012-07-27 15:14 UTC] cataphract@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC