php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67357 Cloned NumberFormatter object loses attributes
Submitted: 2014-05-29 04:32 UTC Modified: 2015-01-19 08:01 UTC
Votes:2
Avg. Score:4.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: roman dot kulish at gmail dot com Assigned: stas (profile)
Status: Closed Package: intl (PECL)
PHP Version: 5.5.12 OS: all
Private report: No CVE-ID: None
 [2014-05-29 04:32 UTC] roman dot kulish at gmail dot com
Description:
------------
It seems that a cloned NumberFormatter object loses attributes set to the original object.

I tried setting attributes in both NumberFormatter::setTextAttribute() and NumberFormatter::setAttribute() and they were not transferred to the cloned object.

It may affect other intl object that has custom attributes.

Test script:
---------------
$fmt = NumberFormatter::create('en', NumberFormatter::DURATION);
$fmt->setTextAttribute(NumberFormatter::DEFAULT_RULESET, "%with-words");

$fmt_clone = clone $fmt;

var_dump($fmt->getTextAttribute(NumberFormatter::DEFAULT_RULESET), $fmt_clone->getTextAttribute(NumberFormatter::DEFAULT_RULESET));

$fmt = NumberFormatter::create('en', NumberFormatter::DECIMAL);
$fmt->setAttribute(NumberFormatter::FRACTION_DIGITS, 2);

$fmt_clone = clone $fmt;

var_dump($fmt->getAttribute(NumberFormatter::FRACTION_DIGITS), $fmt_clone->getTextAttribute(NumberFormatter::FRACTION_DIGITS));


Expected result:
----------------
string(9) "%with-words"
string(9) "%with-words"
int(2)
int(2)

Actual result:
--------------
string(11) "%with-words"
string(9) "%duration"
int(2)
bool(false)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-07 06:30 UTC] stas@php.net
Looks like this is an upstream library problem - same happens in pure C when using unum_clone. Filed http://bugs.icu-project.org/trac/ticket/10996 with ICU, let's see what they say.
 [2014-07-07 06:41 UTC] stas@php.net
-Status: Open +Status: Analyzed
 [2015-01-17 13:57 UTC] danack@php.net
The upstream bug was updated as a duplicate of http://bugs.icu-project.org/trac/ticket/5186

"..this appears to be fixed as of v53.1 so I assume you are running an older version? Upgrading to that release should solve your issue."
 [2015-01-19 08:01 UTC] stas@php.net
-Status: Analyzed +Status: Closed -Assigned To: +Assigned To: stas
 [2015-01-19 08:01 UTC] stas@php.net
Works for me now with ICU 54. So closing it, please reopen if still happens on ICU 54+.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 08:01:27 2024 UTC