php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: chatfielddaniel at googlemail dot com
New email:
PHP Version: OS:

 

 [2011-04-14 12:59 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-19 08:46 UTC] aharvey@php.net
-Status: Open +Status: Bogus -Package: Unknown/Other Function +Package: Strings related
 [2011-04-19 08:46 UTC] aharvey@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC