php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60166 Locale::lookup() returns an empty string if the first arg is an empty array
Submitted: 2011-10-29 11:24 UTC Modified: 2016-04-09 16:50 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: np dot viktorov at gmail dot com Assigned:
Status: Not a bug Package: intl (PECL)
PHP Version: Irrelevant OS: Debian GNU/Linux 6.0.2 (squeeze)
Private report: No CVE-ID: None
 [2011-10-29 11:24 UTC] np dot viktorov at gmail dot com
Description:
------------
Locale::lookup() will return an empty string if the first argument is an empty array() no matter that we have already set the default argument (argument #4)

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

$available = array();
$default = "en";
$requested = "eu-us";

$result = Locale::lookup($available, $requested, null, $default);

var_dump($result);

/*
if we create atleast one element, for example "de" it will work fine
*/

Expected result:
----------------
According to the documentation we should expect to get "en" because this is the default locale provided as the fourth argument. This doesn't happen.

Actual result:
--------------
The actual result is "" (an empty string), not null, not false, just an empty string.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-10-29 11:29 UTC] np dot viktorov at gmail dot com
I forgot the INTL information.
According to phpinfo() the INTL version information is this:
 - version 	1.1.0
 - ICU version 	4.4.1
 [2011-10-31 16:10 UTC] fa@php.net
-Status: Open +Status: Analyzed
 [2011-10-31 16:10 UTC] fa@php.net
RFC4647 (http://www.ietf.org/rfc/rfc4647.txt) states:

3.4.1.  Default Values

   Each application, protocol, or specification that uses lookup MUST
   define the defaulting behavior when no tag matches the language
   priority list.  What this action consists of strongly depends on how
   lookup is being applied.  Some examples of defaulting behavior
   include:

   o  return an item with no language tag or an item of a non-linguistic
      nature, such as an image or sound
   o  return a null string as the language tag value, in cases where the
      protocol permits the empty value (see, for example, "xml:lang" in
      [XML10])
   o  return a particular language tag designated for the operation
   o  return the language tag "i-default" (see [RFC2277])
   o  return an error condition or error message
   o  return a list of available languages for the user to select from

---------------------
So this *might* be classified "unexpected behavior" instead of a bug.

The fix would probably be easy, PHP_5_3/ext/intl/locale_methods.c,1537 :

»···if( !hash_arr || zend_hash_num_elements( hash_arr ) == 0 ) {
»···»···RETURN_EMPTY_STRING();
»···}

But as I have no clue what this would break, I will not change this now.
 [2016-04-09 16:50 UTC] ab@php.net
-Status: Analyzed +Status: Not a bug
 [2016-04-09 16:50 UTC] ab@php.net
One can argue, but to the current situation it is not a bug. The doc page states, that locale_lookup() "Searches the language tag list for the best match to the language". If the tag list is empty, there is no single tag to match and the empty result is an obvious consequence. However when the tag list is not empty, the passed default should not be ignored (that's why I considered bug #66289 as a bug).

Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 04:01:28 2024 UTC