Bug #81383 [NEW]: Locale::lookup / locale_lookup incorrectly returns null instead of default

From: Date: Thu, 26 Aug 2021 02:16:03 +0000
Subject: Bug #81383 [NEW]: Locale::lookup / locale_lookup incorrectly returns null instead of default
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236077@lists.php.net to get a copy of this message
From:             adrien dot crivelli at gmail dot com
Operating system: Ubuntu 20.04.3 LTS
PHP version:      8.0.9
Package:          *Languages/Translation
Bug Type:         Bug
Bug description:Locale::lookup / locale_lookup incorrectly returns null instead of default

Description:
------------
According to official documentation on
https://www.php.net/manual/en/locale.lookup.php,
Locale::lookup will
return the given $default if no match is found. This usually works as
expected, unless if the given $locale is 157 characters long, or more.
Then the $default seems entirely ignored.

I expect that Locale::lookup will always return the $default, whatever
the length of $locale might be.

PHP versions were the bug were confirmed:

```
$ php8.0 --version
PHP 8.0.9 (cli) (built: Jul 30 2021 13:03:39) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.9, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.9, Copyright (c), by Zend Technologies
    with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans
```

```
$ php7.4  --version
PHP 7.4.22 (cli) (built: Jul 30 2021 13:08:17) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.22, Copyright (c), by Zend Technologies
    with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans
```

```
$ php7.2  --version
PHP 7.2.34-23+ubuntu20.04.1+deb.sury.org+1 (cli) (built: Jul  1 2021
16:07:07) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.34-23+ubuntu20.04.1+deb.sury.org+1, Copyright
(c) 1999-2018, by Zend Technologies
    with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans
```

Extract of php8.0 -i that might be relevant:

```
intl

Internationalization support => enabled
ICU version => 66.1
ICU Data version => 66.1
ICU Unicode version => 13.0

Directive => Local Value => Master Value
intl.default_locale => no value => no value
intl.error_level => 0 => 0
intl.use_exceptions => Off => Off
```

Test script:
---------------
<?php

// Expect to see "fr", but get null
var_dump(Locale::lookup(["fr"], str_repeat("a", 157), false, "fr"));

Expected result:
----------------
I expect to get the given default locale of "fr"

Actual result:
--------------
I incorrectly get null

-- 
Edit bug report at https://bugs.php.net/bug.php?id=81383&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=81383&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=81383&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=81383&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=81383&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=81383&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=81383&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=81383&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=81383&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=81383&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=81383&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81383&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=81383&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=81383&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=81383&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=81383&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=81383&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=81383&r=mysqlcfg


Thread (1 message)

  • adrien dot crivelli at gmail dot com
« previous php.bugs (#236077) next »