|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 18:00:01 2025 UTC |
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}}"