fix: use value equality for sortByField tie detection
ClosureExpressionVisitor::sortByField() decided ties with a strict "===" identity check before falling through to the next sort field. For object-typed fields (e.g. two DateTimeImmutable instances that represent the same point in time but are not the same instance), this check never passes, so secondary/tertiary Criteria::orderBy() fields were silently ignored and the resulting comparator was not antisymmetric (swapping the input order of two such elements changed the sort result). Replace the "===" tie check with the same "<=>" comparison already used to determine ordering, so a tie is now detected whenever the values are equal under that comparison, matching value semantics for both scalars and comparable objects. Fixes #437
This commit is contained in:
1 parent
dd6d913ae6
commit
2572a60593
2 files changed
+50
-2
No files matched your search
@@ -170,11 +170,13 @@ class ClosureExpressionVisitor extends ExpressionVisitor
|
||||
$aValue = ClosureExpressionVisitor::getObjectFieldValue($a, $name, $accessRawFieldValues);
|
||||
$bValue = ClosureExpressionVisitor::getObjectFieldValue($b, $name, $accessRawFieldValues);
|
||||
|
||||
if ($aValue === $bValue) {
|
||||
$comparison = $aValue <=> $bValue;
|
||||
|
||||
if ($comparison === 0) {
|
||||
return $next($a, $b);
|
||||
}
|
||||
|
||||
return ($aValue > $bValue ? 1 : -1) * $orientation;
|
||||
return $comparison * $orientation;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user