php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50808 MessageFormatter buggy when using choice formats with nested parameters
Submitted: 2010-01-20 19:47 UTC Modified: 2010-06-16 01:20 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: bschussek at gmail dot com Assigned: stas (profile)
Status: Not a bug Package: I18N and L10N related
PHP Version: 5.3, 6 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bschussek at gmail dot com
New email:
PHP Version: OS:

 

 [2010-01-20 19:47 UTC] bschussek at gmail dot com
Description:
------------
When a message formatter formats choices with nested variables, its behaviour is buggy.

Interestingly, the code below works if you insert the parameter "{1}" once more outside of the choice:

'There are {0,choice,0#are no {1} files|1#is one {1} file} ok {1}'

produces

There are are no text files ok text
There are is one image file ok image

Reproduce code:
---------------
$fmt = MessageFormatter::create('en_GB', 'There are {0,choice,0#are no {1} files|1#is one {1} file} ok');

echo $fmt->format(array(0, "text")), "\n";
echo $fmt->format(array(1, "image")), "\n";

Expected result:
----------------
There are are no text files ok
There are is one image file ok

Actual result:
--------------
There are are no {1} files ok
There are is one {1} file ok

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-21 10:35 UTC] bschussek at gmail dot com
The build of your snapshot doesn't work for me. Did I do anything wrong?

/bin/sh /home/.../php-5.3-latest/libtool --silent --preserve-dup-deps --mode=compile /home/.../php-5.3-latest/meta_ccld -I/usr/include -Iext/intl/ -I/home/.../php-5.3-latest/ext/intl/ -DPHP_ATOM_INC -I/home/.../php-5.3-latest/include -I/home/.../php-5.3-latest/main -I/home/.../php-5.3-latest -I/home/.../php-5.3-latest/ext/date/lib -I/home/.../php-5.3-latest/ext/ereg/regex -I/usr/include/libxml2 -I/usr/include/mysql -I/home/.../php-5.3-latest/ext/sqlite3/libsqlite -I/home/.../php-5.3-latest/TSRM -I/home/.../php-5.3-latest/Zend  -D_REENTRANT -DTHREAD=1  -I/usr/include -g -O2 -fvisibility=hidden -pthread -DZTS  -prefer-non-pic -c /home/.../php-5.3-latest/ext/intl/resourcebundle/resourcebundle_class.c -o ext/intl/resourcebundle/resourcebundle_class.lo 
/home/.../php-5.3-latest/ext/intl/resourcebundle/resourcebundle_class.c: In function ?resourcebundle_ctor?:
/home/.../php-5.3-latest/ext/intl/resourcebundle/resourcebundle_class.c:90: error: too few arguments to function ?zend_object_store_get_object?
/home/.../php-5.3-latest/ext/intl/resourcebundle/resourcebundle_class.c: In function ?resourcebundle_array_count?:
/home/.../php-5.3-latest/ext/intl/resourcebundle/resourcebundle_class.c:250: error: too few arguments to function ?zend_object_store_get_object?
make: *** [ext/intl/resourcebundle/resourcebundle_class.lo] Fehler 1
 [2010-01-21 12:07 UTC] jani@php.net
Stas, no compile here either.
 [2010-01-21 18:09 UTC] stas@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

build fixed
 [2010-01-22 00:48 UTC] bschussek at gmail dot com
The reproduce code still produces the wrong output for me with this  build.
 [2010-06-16 01:20 UTC] stas@php.net
-Status: Assigned +Status: Bogus
 [2010-06-16 01:20 UTC] stas@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Unfortunately, ChoiceFormat it ICU doesn't seem to support formats inside choice alternatives, see: http://icu-project.org/apiref/icu4c/classChoiceFormat.html

Split the pattern like this:
$fmt = MessageFormatter::create('en_GB', 'There are {0,choice,0#are no|1#is one} {1} {0,choice,0#files|1#file} ok');

to make it work.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Aug 08 20:01:32 2020 UTC