php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41758 SORT_LOCALE_STRING broken for sort() in PHP6
Submitted: 2007-06-21 10:19 UTC Modified: 2010-06-13 15:09 UTC
Votes:3
Avg. Score:4.0 ± 0.8
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: hedvall at gmail dot com Assigned: andrei (profile)
Status: Wont fix Package: Arrays related
PHP Version: 6CVS-2007-06-21 (snap) OS: Win2k SP4
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-06-21 10:19 UTC] hedvall at gmail dot com
Description:
------------
According to the documentation for sort(), you must use i18n_loc_set_default() for sort() with SORT_LOCALE_STRING to work in PHP6. However, i18n_loc_set_default() is an undefined function. The documentation instead refers to locale_set_default(). When setting the locale to "sv_SE" (correct) the function returns false, but when setting it to "sv_PHP" (incorrect) the function returns true which is the wrong behavior. The example from locale_set_default() uses "pt_PT" which can be set, but when sorting the result turns out the wrong way. When using locale_get_default() it returns what was set with locale_set_default() even if that function turned it down by returning false.
When later using sort() or asort() (or any other sort) with SORT_LOCALE_STRING the result is the same as a normal sort.

Reproduce code:
---------------
<?php
//Code from the documentation for locale_set_default()

// the list of the strings to sort
$array = array(
    'caramelo',
    'cacto',
    'ca?ada'
);

// set our locale (Portuguese, in this case)
locale_set_default('pt_PT');

// sort using the locale we previously set
sort($array, SORT_LOCALE_STRING);

print_r($array);
?>

Expected result:
----------------
Array
(
    [0] => ca?ada
    [1] => cacto
    [2] => caramelo
)

Actual result:
--------------
Array
(
    [0] => cacto
    [1] => caramelo
    [2] => ca?ada
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-13 15:09 UTC] felipe@php.net
-Status: Assigned +Status: Wont fix
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat May 08 11:01:23 2021 UTC