Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AbstractCollection.php

function AbstractCollection::getComparator

2 calls to AbstractCollection::getComparator()
AbstractCollection::diff in vendor/ramsey/collection/src/AbstractCollection.php
AbstractCollection::intersect in vendor/ramsey/collection/src/AbstractCollection.php

File

vendor/ramsey/collection/src/AbstractCollection.php, line 360

Class

AbstractCollection
This class provides a basic implementation of `CollectionInterface`, to minimize the effort required to implement this interface

Namespace

Ramsey\Collection

Code

private function getComparator() : Closure {
    return function (mixed $a, mixed $b) : int {
        // If the two values are object, we convert them to unique scalars.
        // If the collection contains mixed values (unlikely) where some are objects
        // and some are not, we leave them as they are.
        // The comparator should still work and the result of $a < $b should
        // be consistent but unpredictable since not documented.
        if (is_object($a) && is_object($b)) {
            $a = spl_object_id($a);
            $b = spl_object_id($b);
        }
        return $a === $b ? 0 : ($a < $b ? 1 : -1);
    };
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal