|  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
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: hedvall at gmail dot com
New email:
PHP Version: OS:


 [2007-06-21 10:19 UTC] hedvall at gmail dot com
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:
//Code from the documentation for locale_set_default()

// the list of the strings to sort
$array = array(

// set our locale (Portuguese, in this case)

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


Expected result:
    [0] => ca?ada
    [1] => cacto
    [2] => caramelo

Actual result:
    [0] => cacto
    [1] => caramelo
    [2] => ca?ada


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-13 15:09 UTC]
-Status: Assigned +Status: Wont fix
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 21 20:01:30 2024 UTC