Bug #54530 [Opn->Bgs]: strnatcasecmp treats alphanumeric values before symbols
| From: | aharvey@php.net | Date: | Tue, 19 Apr 2011 06:46:19 +0000 |
| Subject: | Bug #54530 [Opn->Bgs]: strnatcasecmp treats alphanumeric values before symbols | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-160280@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=54530&edit=1
ID: 54530
Updated by: aharvey@php.net
Reported by: chatfielddaniel at googlemail dot com
Summary: strnatcasecmp treats alphanumeric values before
symbols
-Status: Open
+Status: Bogus
Type: Bug
-Package: Unknown/Other Function
+Package: Strings related
Operating System: Windows 7
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Just like all of the other comparison functions, strnatcmp() and
strnatcasecmp() eventually fall back to a straight byte value by byte
value comparison if the "natural" alphanumeric sorting logic isn't
triggered. Since the underscore character has a higher character code
than any number or uppercase letter (and case-insensitive comparisons
are done on uppercased strings), it's always "after" letters and
numbers.
This behaviour isn't going to change.
Previous Comments:
------------------------------------------------------------------------
[2011-04-14 12:59:37] chatfielddaniel at googlemail dot com
Description:
------------
---
From manual page: http://www.php.net/function.strnatcasecmp
---
The strnatcasecmp is set that '_' is after letters and numbers which is
illogical
and should be changed.
Test script:
---------------
echo strnatcasecmp('1','2');//-1
echo strnatcasecmp('_','2');//1 (incorrect)
echo strnatcasecmp('_','a');//1 (incorrect)
echo strnatcasecmp('a','b');//-1
echo strnatcasecmp(2,'a');//-1
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=54530&edit=1