We wrote some code involving usort which works fine on our development systems (PHP 5.2.8), but are experiencing a problem on our live systems (PHP 5.2.0):
// Sort by distance
usort($locations, 'Interpolator::sortByDistance');
calls the method (within the same class Interpolator):
private static function sortByDistance($a, $b) {
$return = 0;
if($a['distance'] > $b['distance']) {
$return = 1;
} else if ($a['distance'] < $b['distance']) {
$return = -1;
}
return $return;
}
On our live systems, this returns a completely arbitrarily sorted array, the original order is disturbed, but still not sorted by distance.
I cannot find any reference to a PHP bug fixed between 5.2.0 and 5.2.8 relevant to this problem.
Where might this problem be coming from? Can I fix this short of writing a sorting function myself?