php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79212 NumberFormatter::format() may detect wrong type
Submitted: 2020-02-02 10:44 UTC Modified: 2020-02-03 11:33 UTC
From: cmb@php.net Assigned: cmb (profile)
Status: Closed Package: I18N and L10N related
PHP Version: 7.3Git-2020-02-02 (Git) 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: cmb@php.net
New email:
PHP Version: OS:

 

 [2020-02-02 10:44 UTC] cmb@php.net
Description:
------------
If ::format() is called with ::TYPE_DEFAULT, but the value is an
object which implements cast to number, the type is erroneously
assumed to be ::TYPE_INT32.

This issue has been reported by googleguy@php.net in r11.


Test script:
---------------
<?php
$fmt = new NumberFormatter('en_US', NumberFormatter::SPELLOUT);
var_dump($fmt->format(gmp_init('823749273428379492374')));
?>


Expected result:
----------------
string(157) "eighteen quadrillion fourteen trillion three hundred ninety-eight billion five hundred nine million four hundred eighty-one thousand nine hundred eighty-four"


Actual result:
--------------
string(108) "minus one billion one hundred twenty-nine million four hundred forty-seven thousand four hundred twenty-four"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-02-02 11:20 UTC] cmb@php.net
Well, the expected result above is obviously wrong, but
apparently, we're additionally hitting an ICU4C bug here[1].

Anyhow, using ::PATTERN_DECIMAL instead of ::SPELLOUT, we get

    string(11) "-1129447424"

while we should expect

    string(21) "823749273428379400000"

[1] <https://unicode-org.atlassian.net/browse/ICU-8223>
 [2020-02-03 11:31 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=c2935499b14ee605452016ea00f3c0a94c0a1943
Log: Fix #79212: NumberFormatter::format() may detect wrong type
 [2020-02-03 11:31 UTC] cmb@php.net
-Status: Open +Status: Closed
 [2020-02-03 11:33 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 09:01:30 2024 UTC