Bug #69158 [NEW]: Inconsistency: usort does not return the same result on PHP < 7 and PHP7

From: Date: Mon, 02 Mar 2015 14:49:01 +0000
Subject: Bug #69158 [NEW]: Inconsistency: usort does not return the same result on PHP < 7 and PHP7
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191044@lists.php.net to get a copy of this message
From: contact at jubianchi dot fr Operating system: PHP version: master-Git-2015-03-02 (Git) Package: Arrays related Bug Type: Bug Bug description:Inconsistency: usort does not return the same result on PHP < 7 and PHP7 Description: ------------ There is a tiny difference on usort result between php < 7 and php7 (master): items are not ordered the same way between those versions. PHP7 seems to be consistent with HVVM but not with earlier version of PHP :) Test script: --------------- <?php // http://3v4l.org/RYTt9 $array = array( array( 'file' => 'file1', 'line' => 1, 'message' => 'foo' ), array( 'file' => 'file1', 'line' => 1, 'message' => 'bar' ) ); usort($array, function($a, $b) { if ($a['file'] !== $b['file']) { return strcmp($a['file'], $b['file']); } else if ($a['line'] === $b['line']) { return 0; } else { return ($a['line'] < $b['line'] ? -1 : 1); } } ); var_dump($array); Expected result: ---------------- array(2) { [0]=> array(3) { ["file"]=> string(5) "file1" ["line"]=> int(1) ["message"]=> string(3) "bar" } [1]=> array(3) { ["file"]=> string(5) "file1" ["line"]=> int(1) ["message"]=> string(3) "foo" } } Actual result: -------------- array(2) { [0]=> array(3) { ["file"]=> string(5) "file1" ["line"]=> int(1) ["message"]=> string(3) "foo" } [1]=> array(3) { ["file"]=> string(5) "file1" ["line"]=> int(1) ["message"]=> string(3) "bar" } } -- Edit bug report at https://bugs.php.net/bug.php?id=69158&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69158&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69158&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69158&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=69158&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=69158&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=69158&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=69158&r=needscript Try newer version: https://bugs.php.net/fix.php?id=69158&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=69158&r=support Expected behavior: https://bugs.php.net/fix.php?id=69158&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=69158&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=69158&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=69158&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69158&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=69158&r=dst IIS Stability: https://bugs.php.net/fix.php?id=69158&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=69158&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=69158&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=69158&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=69158&r=mysqlcfg

« previous php.bugs (#191044) next »