Bug #72835 [NEW]: Alphanumeric sort inconsistent

From: Date: Mon, 15 Aug 2016 03:53:03 +0000
Subject: Bug #72835 [NEW]: Alphanumeric sort inconsistent
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203284@lists.php.net to get a copy of this message
From: j dot david dot rothschild at gmail dot com Operating system: Windows, Linux PHP version: 7.0.9 Package: *General Issues Bug Type: Bug Bug description:Alphanumeric sort inconsistent Description: ------------ I'm experiencing an issue where calling max() on an array of strings produces an incorrect result. I understand that with an array of strings, max() compares the strings alphanumerically, and picks the "highest". But this is not always the case. Out of curiosity I tried doing sort() on the array to see how the alphanumeric sort was playing out, and here also the results are not what you would expect. I ran the test script below on 3v4l.org and see that with this example max() fails on every version from the latest down. However, interestingly, sort() returns the expected result on <= 5.6.24 (but not from 7.0.0 up). Test script: --------------- <?php //see https://3v4l.org/93ac5 $new_array = array( "8000", "12345", "6811-1", "7031", "6841" ); var_dump(max($new_array)); // would expect "8000", but returns "7031" sort($new_array); // let's see how the alphanum sort is looking at this... var_dump($new_array); // and it's wonky... why isn't "8000" at the end? Expected result: ---------------- string(4) "8000" array(5) { [0]=> string(5) "12345" [1]=> string(6) "6811-1" [2]=> string(4) "6841" [3]=> string(4) "7031" [4]=> string(4) "8000" } Actual result: -------------- string(4) "7031" array(5) { [0]=> string(4) "8000" [1]=> string(5) "12345" [2]=> string(6) "6811-1" [3]=> string(4) "6841" [4]=> string(4) "7031" } -- Edit bug report at https://bugs.php.net/bug.php?id=72835&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72835&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72835&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72835&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=72835&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=72835&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=72835&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=72835&r=needscript Try newer version: https://bugs.php.net/fix.php?id=72835&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=72835&r=support Expected behavior: https://bugs.php.net/fix.php?id=72835&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=72835&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=72835&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=72835&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72835&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=72835&r=dst IIS Stability: https://bugs.php.net/fix.php?id=72835&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=72835&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=72835&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=72835&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=72835&r=mysqlcfg

« previous php.bugs (#203284) next »