php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74063 NumberFormatter fails after retrieval from session
Submitted: 2017-02-08 17:28 UTC Modified: 2020-01-30 09:16 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: mrfellows at gmail dot com Assigned: cmb (profile)
Status: Closed Package: intl (PECL)
PHP Version: 7.0.15 OS: ubuntu 16.04.1
Private report: No CVE-ID: None
 [2017-02-08 17:28 UTC] mrfellows at gmail dot com
Description:
------------
A NumberFormatter instance retrieved from the session generates an 

'Found unconstructed NumberFormatter: U_ILLEGAL_ARGUMENT_ERROR'

on calling ::format(). 

The code snippet below can be run from the in-built webserver.  The second time the page is requested (within a session), the above error is reported.

Test script:
---------------
session_start();

if(isset($_SESSION["currencyFormatter"])){
    $formatter = $_SESSION["currencyFormatter"];
    echo "loaded formatter from session\n";
} else {
    echo "no formatter on session\n";
    $formatter = new NumberFormatter("en_GB", NumberFormatter::CURRENCY);
    $_SESSION["currencyFormatter"] = $formatter;
}

var_dump($formatter->format(123, NumberFormatter::CURRENCY));
if(intl_is_failure($formatter->getErrorCode())) {
    echo "\n" . $formatter->getErrorMessage();
}

session_commit();

Expected result:
----------------
First request:

no formatter on session
string '£123.00' (length=8)

Subsequent requests:

loaded formatter from session
string '£123.00' (length=8)

Actual result:
--------------
First request:

no formatter on session
string '£123.00' (length=8)

Subsequent requests:

loaded formatter from session
boolean false
Found unconstructed NumberFormatter: U_ILLEGAL_ARGUMENT_ERROR

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-09 15:01 UTC] andrew dot nester dot dev at gmail dot com
Thanks for pointing out this issue! Just added PR fixing this.
 [2017-03-27 13:06 UTC] testingteam2 at gmail dot com
I am using Magento 2 so enable Intl module.
When enable extension=php_intl.dll 
Then generate error "Fatal error: Class 'IntlDateFormatter' not found"

Check by command line, then giving warning
"PHP Warning:  PHP Startup: Unable to load dynamic library 'E:\xampp\php\ext\php_
intl.dll' - %1 is not a valid Win32 application.
 in Unknown on line 0 "

So please suggest me how to resolve it.
Thanks.
 [2020-01-26 16:04 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2020-01-26 16:04 UTC] cmb@php.net
I can confirm this issue; however, it is not related to sessions
in particular, but rather that unserialization of NumberFormatter
instances is not (yet) supported.

Since there is no agreed upon solution how to do this
unserialization, it seems to be sensible to disallow serialization
in the first place for now.
 [2020-01-26 16:06 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #74063: NumberFormatter fails after retrieval from session
On GitHub:  https://github.com/php/php-src/pull/5116
Patch:      https://github.com/php/php-src/pull/5116.patch
 [2020-01-30 09:13 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=146848429605752e156a9f0ced4bfb079720d094
Log: Fix #74063: NumberFormatter fails after retrieval from session
 [2020-01-30 09:13 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2020-01-30 09:15 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2020-01-30 09:16 UTC] cmb@php.net
To clarify: this issue has been "fixed" in the master branch by
disallowing serialization and unserialization of NumberFormatter
instances altogether.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 10:01:28 2024 UTC