#41758 [NEW]: SORT_LOCALE_STRING broken for sort() in PHP6
| From: | hedvall at gmail dot com | Date: | Thu, 21 Jun 2007 10:19:31 +0000 |
| Subject: | #41758 [NEW]: SORT_LOCALE_STRING broken for sort() in PHP6 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-113989@lists.php.net to get a copy of this message | ||
From: hedvall at gmail dot com
Operating system: Win2k SP4
PHP version: 6CVS-2007-06-21 (snap)
PHP Bug Type: Arrays related
Bug description: SORT_LOCALE_STRING broken for sort() in PHP6
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
)
--
Edit bug report at http://bugs.php.net/?id=41758&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41758&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41758&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41758&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=41758&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=41758&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=41758&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=41758&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=41758&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=41758&r=support
Expected behavior: http://bugs.php.net/fix.php?id=41758&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=41758&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=41758&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=41758&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41758&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=41758&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=41758&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=41758&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=41758&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=41758&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=41758&r=mysqlcfg