From: carsten_sttgt at gmx dot de
Operating system: Windows_NT
PHP version: 5.2.8
PHP Bug Type: Strings related
Bug description: strnatcmp: char instead of unsigned char
Description:
------------
Hello,
why is the nat_char defined as char instead of unsigned char?
char limit us (and a correct sorting) to ASCII 0-127. With a unsigned char
(ASCII 0-255) the sorting is "correct" for all single byte charsets like
iso-8850-1 (which is the default in PHP).
Internally the function is already doing a cast to unsigned char many
times (but not in the main comparison).
In the original header (strnatcmp.h) from the author, the typedef for
nat_char is also only a hint.
Regards,
Carsten
Reproduce code:
---------------
<?php
$daten = array('Süden','spielen','Sonne','Wind','Regen','Meer');
natcasesort($daten);
print_r($daten);
?>
Expected result:
----------------
Array
(
[5] => Meer
[4] => Regen
[2] => Sonne
[1] => spielen
[0] => Süden
[3] => Wind
)
Actual result:
--------------
Array
(
[5] => Meer
[4] => Regen
[0] => Süden
[2] => Sonne
[1] => spielen
[3] => Wind
)
--
Edit bug report at http://bugs.php.net/?id=47481&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=47481&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=47481&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=47481&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=47481&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=47481&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=47481&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=47481&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=47481&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=47481&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=47481&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=47481&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=47481&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=47481&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=47481&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47481&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47481&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=47481&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=47481&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=47481&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=47481&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=47481&r=mysqlcfg