php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72809 Locale::lookup() / locale_lookup() wrong result with canonicalize option
Submitted: 2016-08-11 08:20 UTC Modified: -
Votes:4
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:-1 (-25.0%)
From: a dot schilder at gmx dot de Assigned:
Status: Open Package: intl (PECL)
PHP Version: 7.1.0beta2 OS: Windows 10 Pro
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-08-11 08:20 UTC] a dot schilder at gmx dot de
Description:
------------
When I call Locale::lookup as follows, I get the expected result 'en-US':
Locale::lookup(['en', 'en-US'], 'en-US-u-cu-EUR-tz-deber-fw-mon', false);

I should get the same result when using the canonicalize option, because following the docs all "arguments will be converted to canonical form before matching" and after conversion, they should still match - but I get 'en' instead of the expected locale 'en-US':
Locale::lookup(['en', 'en-US'], 'en-US-u-cu-EUR-tz-deber-fw-mon', true);

I also get 'en' when using the canonicalized versions directly (no matter if the
canonicalize option is set or not):
echo Locale::lookup(['en', 'en_US'], 'en_US@currency=eur;fw=mon;timezone=Europe/Berlin', false) . PHP_EOL;
echo Locale::lookup(['en', 'en_US'], 'en_US@currency=eur;fw=mon;timezone=Europe/Berlin', true) . PHP_EOL;

Test script:
---------------
<?php
echo Locale::lookup(['en', 'en-US'], 'en-US-u-cu-EUR-tz-deber-fw-mon', false) . PHP_EOL;
echo PHP_EOL;
echo Locale::canonicalize('en-US-u-cu-EUR-tz-deber-fw-mon') . PHP_EOL;
echo Locale::canonicalize('en-US') . PHP_EOL;
echo Locale::canonicalize('en') . PHP_EOL;
echo PHP_EOL;
echo Locale::lookup(['en', 'en-US'], 'en-US-u-cu-EUR-tz-deber-fw-mon', true) . PHP_EOL;
echo Locale::lookup(['en', 'en_US'], 'en_US@currency=eur;fw=mon;timezone=Europe/Berlin', false) . PHP_EOL;
echo Locale::lookup(['en', 'en_US'], 'en_US@currency=eur;fw=mon;timezone=Europe/Berlin', true) . PHP_EOL;

Expected result:
----------------
en-US

en_US@currency=eur;fw=mon;timezone=Europe/Berlin
en_US
en

en-US
en_US
en_US

Actual result:
--------------
en-US

en_US@currency=eur;fw=mon;timezone=Europe/Berlin
en_US
en

en
en
en

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Aug 26 07:01:26 2019 UTC