# sebastianbergmann/comparator

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/sebastianbergmann-comparator).**

7,053 stars · 70 forks · PHP · BSD-3-Clause

## Links

- GitHub: https://github.com/sebastianbergmann/comparator
- awesome-repositories: https://awesome-repositories.com/repository/sebastianbergmann-comparator.md

## Description

This library is a data assertion tool and equality logic framework for PHP. It provides utilities to verify that two values, nested objects, or complex data types match based on their internal contents.

The project distinguishes itself through the use of custom matching rules and configurable precision. It allows for the comparison of floating point numbers and dates using a defined margin of error to account for numeric precision loss.

The framework covers deep value equality verification across scalars, arrays, and nested objects. It implements strict type enforcement to prevent implicit conversions and uses recursive traversal to analyze internal data structures for integrity validation.

## Tags

### Software Engineering & Architecture

- [Deep Equality Comparison](https://awesome-repositories.com/f/software-engineering-architecture/deep-equality-comparison.md) — Provides utilities for recursively comparing nested data structures and objects by value rather than reference. ([source](https://github.com/sebastianbergmann/comparator/blob/main/phpstan.neon))
- [Type-Safe Equality Enforcements](https://awesome-repositories.com/f/software-engineering-architecture/execution-control/equality-validators/equality-operators/type-safe-equality-enforcements.md) — Prevents implicit type conversion during comparison to ensure that only identical data types are considered equal.
- [Type-Aware Matching](https://awesome-repositories.com/f/software-engineering-architecture/pattern-matching-libraries/type-aware-matching.md) — Validates that both values share the same internal PHP type before proceeding to compare their contents.
- [Data Structure Traversers](https://awesome-repositories.com/f/software-engineering-architecture/recursive-validation-engines/recursive-tree-traversers/data-structure-traversers.md) — Recursively walks through nested arrays and objects to verify the integrity of every element in the data structure.

### Data & Databases

- [Tolerant Type Comparisons](https://awesome-repositories.com/f/data-databases/value-comparators/epsilon-based-type-comparators/custom-data-comparators/comparable-type-comparisons/tolerant-type-comparisons.md) — Allows comparison of complex types, such as dates and numbers, using specified tolerance levels to determine equality. ([source](https://github.com/sebastianbergmann/comparator/blob/main/ChangeLog.md))
- [Structural Data Validators](https://awesome-repositories.com/f/data-databases/structural-data-validators.md) — Verifies if data sets or configuration arrays match by analyzing their internal structure and scalar values.

### Programming Languages & Runtimes

- [Equality Logic Frameworks](https://awesome-repositories.com/f/programming-languages-runtimes/programming-utilities/data-structure-type-helpers/data-structure-utilities/deep-equality-checking/equality-logic-frameworks.md) — Implements a framework for comparing scalars, arrays, and objects with configurable precision and strict type checking.

### Scientific & Mathematical Computing

- [Precision-Tolerant Comparisons](https://awesome-repositories.com/f/scientific-mathematical-computing/floating-point-arithmetic/precision-tolerant-comparisons.md) — Determines equality for floating point numbers and decimals by checking if the difference falls within a specified numeric range.

### Testing & Quality Assurance

- [PHP Data Assertion Tools](https://awesome-repositories.com/f/testing-quality-assurance/php-data-assertion-tools.md) — Provides a specialized tool for verifying that PHP values or nested objects match based on internal contents.
- [PHP Value Comparators](https://awesome-repositories.com/f/testing-quality-assurance/php-value-comparators.md) — Compares complex PHP data types and nested objects to determine equality based on internal contents.
- [PHP Value Comparison Libraries](https://awesome-repositories.com/f/testing-quality-assurance/php-value-comparison-libraries.md) — Provides a comprehensive library for checking equality between complex PHP data types using custom tolerance and matching rules.
- [PHP Testing Frameworks](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/testing-frameworks/end-to-end-testing-suites/end-to-end-testing-frameworks/php-testing-frameworks.md) — Provides flexible equality checks and numeric tolerances for verifying actual output against expected values in PHP test suites.
