|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54530 strnatcasecmp treats alphanumeric values before symbols
Submitted: 2011-04-14 12:59 UTC Modified: 2011-04-19 08:46 UTC
From: chatfielddaniel at googlemail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: Irrelevant OS: Windows 7
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: chatfielddaniel at googlemail dot com
New email:
PHP Version: OS:


 [2011-04-14 12:59 UTC] chatfielddaniel at googlemail dot com
From manual page:
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-19 08:46 UTC]
-Status: Open +Status: Bogus -Package: Unknown/Other Function +Package: Strings related
 [2011-04-19 08:46 UTC]
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.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Oct 20 03:01:23 2020 UTC