Bug #60166 [Opn->Ana]: Locale::lookup() returns an empty string if the first arg is an empty array
| From: | fa@php.net | Date: | Mon, 31 Oct 2011 16:10:18 +0000 |
| Subject: | Bug #60166 [Opn->Ana]: Locale::lookup() returns an empty string if the first arg is an empty array | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-164729@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60166&edit=1
ID: 60166
Updated by: fa@php.net
Reported by: np dot viktorov at gmail dot com
Summary: Locale::lookup() returns an empty string if the
first arg is an empty array
-Status: Open
+Status: Analyzed
Type: Bug
Package: intl
Operating System: Debian GNU/Linux 6.0.2 (squeeze)
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2011-10-29 11:29:11] 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-29 11:24:32] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60166&edit=1