php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49698 Unexpected change in strnatcasecmp()
Submitted: 2009-09-28 07:56 UTC Modified: 2009-09-28 13:31 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: sander dot vink at procurios dot nl Assigned:
Status: Closed Package: Strings related
PHP Version: 5.2.11 OS: Linux
Private report: No CVE-ID: None
 [2009-09-28 07:56 UTC] sander dot vink at procurios dot nl
Description:
------------
We use the strnatcasecmp()-function to get a "natural order" in our 
lists of items. Up until PHP 5.2.9 it worked like a charm, but since we 
upgraded to PHP 5.2.11 the order seems to have been changed.

The natural order is used in our case to support the sorting of items 
that have been prefixed with numbers (0, 1, 2, etc). This is exactly 
where the problem arises: 0 should be "sorted" before 1, but this is no 
longer the case.

This problem also occurs in the latest snapshot of PHP 5.3

Reproduce code:
---------------
<?php

$string1 = '0 Foo';
$string2 = '1 Bar';

var_dump(strnatcasecmp($string1, $string2));

Expected result:
----------------
int(-1)

Actual result:
--------------
int(1)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-28 11:22 UTC] sjoerd@php.net
This seems to be solved already in PHP 5.3-HEAD.
 [2009-09-28 11:49 UTC] sander dot vink at procurios dot nl
I have tried the latest snapshot again (Built on: Sep 28, 2009 10:30 
UTC) and the expected result is still not acquired.

Are you sure it is fixed in PHP 5.3-HEAD, and if so, when will it be 
available as either snapshot or release?
 [2009-09-28 11:51 UTC] sander dot vink at procurios dot nl
To be a little more specific, I used the latest snapshot of PHP 5.3 
(shown as "PHP 5.3.2-dev").
 [2009-09-28 13:29 UTC] svn@php.net
Automatic comment from SVN on behalf of rasmus
Revision: http://svn.php.net/viewvc/?view=revision&revision=288896
Log: Fix for bug #49698
 [2009-09-28 13:31 UTC] rasmus@php.net
I have fixed this regression, although if you have an integer prefix on your strings, I am not sure why you are using strnatcasecmp on those.
 [2009-10-09 14:33 UTC] svn@php.net
Automatic comment from SVN on behalf of pajoye
Revision: http://svn.php.net/viewvc/?view=revision&revision=289419
Log: - Merge: Fix for bug #49698
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC