PHPackages                             eloquent/equality - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. eloquent/equality

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

eloquent/equality
=================

A better strict comparison for PHP.

2.1.2(12y ago)158.5k2MITPHPPHP &gt;=5.3

Since Nov 8Pushed 12y ago2 watchersCompare

[ Source](https://github.com/eloquent/equality)[ Packagist](https://packagist.org/packages/eloquent/equality)[ Docs](https://github.com/eloquent/equality)[ RSS](/packages/eloquent-equality/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (9)Dependencies (1)Versions (11)Used By (2)

Equality
========

[](#equality)

*A better strict comparison for PHP.*

[![The most recent stable version is 2.1.2](https://camo.githubusercontent.com/43d68b8c10c6c4466a1639113df599e36ecb4bdc21c5155e7c26e40944aac59e/687474703a2f2f696d672e736869656c64732e696f2f3a73656d7665722d322e312e322d627269676874677265656e2e737667 "This project uses semantic versioning")](http://semver.org/)[![Current build status image](https://camo.githubusercontent.com/68607574d12a642fefd615fbff5cb3757312bb36475e43304420251abd11303d/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f656c6f7175656e742f657175616c6974792f646576656c6f702e737667 "Current build status for the develop branch")](https://travis-ci.org/eloquent/equality)[![Current coverage status image](https://camo.githubusercontent.com/864d610afa471d4bf7ced4d8f862ecd91fba4d83cd839436e0cda37df963262c/687474703a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f656c6f7175656e742f657175616c6974792f646576656c6f702e737667 "Current test coverage for the develop branch")](https://coveralls.io/r/eloquent/equality)

Deprecated
----------

[](#deprecated)

*Equality* is deprecated. Please use [Parity](https://github.com/IcecaveStudios/parity) instead.

Installation and documentation
------------------------------

[](#installation-and-documentation)

- Available as [Composer](http://getcomposer.org/) package [eloquent/equality](https://packagist.org/packages/eloquent/equality).
- [API documentation](http://lqnt.co/equality/artifacts/documentation/api/) available.

The problem
-----------

[](#the-problem)

Sometimes it is necessary to compare two objects to determine whether they are considered equal.

If the `==` operator is used, there is no strictness about the equality. For instance, this snippet outputs 'equal':

```
$left = new stdClass;
$left->foo = 0;

$right = new stdClass;
$right->foo = null;

if ($left == $right) {
    echo 'equal';
} else {
    echo 'not equal';
}
```

Conversely, if the `===` operator is used, objects are not equal unless they are the same *instance*. The following snippet outputs 'not equal':

```
$left = new stdClass;
$left->foo = 'bar';

$right = new stdClass;
$right->foo = 'bar';

if ($left === $right) {
    echo 'equal';
} else {
    echo 'not equal';
}
```

Unfortunately PHP does not have an inbuilt method to compare objects strictly without requiring that they be the same instance. This is where *Equality* comes in. This snippet correctly outputs 'equal':

```
use Eloquent\Equality\Comparator;

$left = new stdClass;
$left->foo = 'bar';

$right = new stdClass;
$right->foo = 'bar';

$comparator = new Comparator;

if ($comparator->equals($left, $right)) {
    echo 'equal';
} else {
    echo 'not equal';
}
```

Usage
-----

[](#usage)

*Equality* is very simple to use. Simply instantiate a `Comparator` and use its `equals()` method:

```
use Eloquent\Equality\Comparator;

$comparator = new Comparator;

if ($comparator->equals($left, $right)) {
    // equal
} else {
    // not equal
}
```

*Equality* can work with any PHP data type, not just objects.

Custom equality logic
---------------------

[](#custom-equality-logic)

In some cases it may be desirable to customize how equality is determined. The interface `EqualityComparable` can be used to provide a custom equality implementation for any class:

```
use Eloquent\Equality\Comparator;
use Eloquent\Equality\EqualityComparable;

class Foo implements EqualityComparable
{
    /**
     * @param mixed $value
     * @param Comparator $comparator
     *
     * @return boolean
     */
    public function isEqualTo($value, Comparator $comparator)
    {
        // custom logic...
    }
}
```

When *Equality* encounters an object that implements `EqualityComparable`, it will return the result of the `isEqualTo()` method instead of using the default equality logic. The comparator itself will be passed as the second parameter.

How does *Equality* work?
-------------------------

[](#how-does-equality-work)

*Equality* uses [reflection](http://php.net/reflection) to recurse over the values it is passed and ensure that they are deeply, and strictly, equal.

In addition, it implements special protections to avoid infinite recursion issues, such as objects that contain themselves, or objects that contain the object that they are being compared to.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 94.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~57 days

Recently: every ~115 days

Total

9

Last Release

4479d ago

Major Versions

1.2.0 → 2.0.02012-11-09

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

2.1.2PHP &gt;=5.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/100152?v=4)[Erin](/maintainers/ezzatron)[@ezzatron](https://github.com/ezzatron)

---

Top Contributors

[![ezzatron](https://avatars.githubusercontent.com/u/100152?v=4)](https://github.com/ezzatron "ezzatron (17 commits)")[![jmalloc](https://avatars.githubusercontent.com/u/761536?v=4)](https://github.com/jmalloc "jmalloc (1 commits)")

---

Tags

objectequalitycomparisonstrictdeep

### Embed Badge

![Health badge](/badges/eloquent-equality/health.svg)

```
[![Health](https://phpackages.com/badges/eloquent-equality/health.svg)](https://phpackages.com/packages/eloquent-equality)
```

###  Alternatives

[myclabs/deep-copy

Create deep copies (clones) of your objects

8.9k849.8M169](/packages/myclabs-deep-copy)[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k9.2M108](/packages/cuyz-valinor)[icecave/parity

A customizable deep comparison library.

516.8M10](/packages/icecave-parity)[consistence/consistence

Consistence - consistent approach and additions to PHP's functionality

1831.1M18](/packages/consistence-consistence)[phootwork/lang

Missing PHP language constructs

1224.8M8](/packages/phootwork-lang)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
