php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60148 Cannot select rule set when using NumberFormatter with pattern rule based
Submitted: 2011-10-27 14:33 UTC Modified: 2015-08-18 17:28 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: rgasler at streamwide dot ro Assigned:
Status: Open Package: intl (PECL)
PHP Version: 5.3.8 OS: Ubuntu 11.04
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.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: rgasler at streamwide dot ro
New email:
PHP Version: OS:

 

 [2011-10-27 14:33 UTC] rgasler at streamwide dot ro
Description:
------------
According to the RuleBasedNumberFormat documentation: http://www.icu-
project.org/apiref/icu4c/classRuleBasedNumberFormat.html#details, a rule pattern 
string can have multiple rule sets.
When calling the format method, it is possible to select the rule set to use. 

But it PHP seems that this is not possible in the current implementation:

NumberFormatter::string format ( number $value [, int $type ] )

Notice that $type is an integer and may take only these possible values:
NumberFormatter::TYPE_DEFAULT
NumberFormatter::TYPE_INT32
NumberFormatter::TYPE_INT64
NumberFormatter::TYPE_DOUBLE
NumberFormatter::TYPE_CURRENCY

For rule set selection to work $type should be a string (the rule set name).


Test script:
---------------
$ruleSet='
%spellout-cardinal:
1:one;
%spellout-ordinal:
1:first;
';

$formatter = new NumberFormatter(null, NumberFormatter::PATTERN_RULEBASED, $ruleSet);

echo $formatter->format(1, 'spellout-ordinal');

Expected result:
----------------
first

Actual result:
--------------
PHP Warning:  NumberFormatter::format() expects parameter 2 to be long, string 
given in /home/raducu/Workspace/Spelling/numbers.php on line 12

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-19 13:02 UTC] clicky at erebot dot net
You're correct in saying it is not possible to select the ruleset when calling format(). But there is a workaround.

You can use the setTextAttribute() method with the NumberFormatter::DEFAULT_RULESET attribute to select the ruleset.
See my comment here for more information: http://php.net/manual/en/numberformatter.create.php#94628 (internally, NumberFormatter::DURATION uses a ruleset).
 [2015-08-18 17:28 UTC] cmb@php.net
-Type: Bug +Type: Feature/Change Request
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Sep 19 18:03:37 2021 UTC