finds.dev← search

// the find

sebastianbergmann/comparator

★ 7,053 · PHP · BSD-3-Clause · updated Jul 2026

Provides the functionality to compare PHP values for equality.

A PHP library that handles value comparison with type-aware logic — it knows that two DateTime objects in different timezones can be equal, that SplObjectStorage needs special treatment, and that a mock object should be compared by its expectations rather than its internal state. It is the comparison engine underneath PHPUnit and essentially nothing else; you almost certainly already have it as a transitive dependency.

The type dispatch via Factory is clean — each comparator handles exactly one PHP type, so adding a custom comparator for your own value objects is straightforward and doesn't require touching the core. DateTime comparison accounts for timezone normalization, which is the one case where naive equality silently lies. The test coverage mirrors the comparator list one-to-one, and the CI setup runs PHPStan at a strict level plus type-coverage checks — this isn't a hobby project. Active maintenance with a push two days ago after years of stewardship.

The public API surface is tiny and frozen — this is intentional, but it means if you need comparison semantics for something outside PHPUnit's mental model (e.g., comparing value objects by domain rules), you're bolting on rather than fitting in naturally. No support for deep partial matching or diff-only output — you get 'equal or not' plus a ComparisonFailure string, which is enough for test assertions but not for general-purpose diffing. The MockObjectComparator is a hard coupling to PHPUnit internals; using this library outside a PHPUnit context drags in concepts that don't belong. Stars are inflated by being a PHPUnit dependency — practically nobody is choosing this library intentionally.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →