PHPackages                             pitpit/php-diff - 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. pitpit/php-diff

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

pitpit/php-diff
===============

Compare variables (array, object, string...) easily

515.2k1[2 PRs](https://github.com/pitpit/php-diff/pulls)2PHP

Since Feb 24Pushed 7y agoCompare

[ Source](https://github.com/pitpit/php-diff)[ Packagist](https://packagist.org/packages/pitpit/php-diff)[ RSS](/packages/pitpit-php-diff/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (2)

PHP Diff
========

[](#php-diff)

A comprehensive library for get differences between two variables (array, object, string...)

Installation
------------

[](#installation)

```
php composer.phar require "pitpit/diff":"@dev"

```

Usage
-----

[](#usage)

Comparing string
----------------

[](#comparing-string)

```
$engine = new \Pitpit\Component\Diff\DiffEngine();
$diff = $engine->compare('test1', 'test2');

echo $diff->isModified();
```

Comparing objects
-----------------

[](#comparing-objects)

```
class MyClassToCompare
{
    public $value;

    public function __construct($value)
    {
        $this->value = $value;
    }

    public function getValue()
    {
        return $this->value;
    }
}

$toCompare1 = new MyClassToCompare(4);
$toCompare2 = new MyClassToCompare(9);

$engine = new \Pitpit\Component\Diff\DiffEngine();

$diff = $engine->compare($toCompare1, $toCompare2);

//this closure iterate on each child properties and display where differences are
$trace = function($diff, $tab = '') use (&$trace) {

    foreach ($diff as $element) {
        $c = $element->isTypeChanged()?'T':($element->isModified()?'M':($element->isCreated()?'+':($element->isDeleted()?'-':'=')));

        // print_r(sprintf("%s* %s [%s -> %s] (%s)\n", $tab, $element->getIdentifier(), is_object($element->getOld())?get_class($element->getOld()):gettype($element->getOld()), is_object($element->getNew())?get_class($element->getNew()):gettype($element->getNew()), $c));
        print_r(sprintf("%s* %s [%s -> %s] (%s)\n", $tab, $element->getIdentifier(), gettype($element->getOld()), gettype($element->getNew()), $c));

        if ($diff->isModified()) {
            $trace($element, $tab . '  ');
        }
    }
};
```

Run the tests
-------------

[](#run-the-tests)

Get and install composer:

The resolve and download dependencies:

```
php composer.phar install

```

Run the tests:

```
phpunit

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/f8abf06489ebaa309c525e136ffa1ad463682ccd7addff0e7199d903132735a5?d=identicon)[pitpit](/maintainers/pitpit)

### Embed Badge

![Health badge](/badges/pitpit-php-diff/health.svg)

```
[![Health](https://phpackages.com/badges/pitpit-php-diff/health.svg)](https://phpackages.com/packages/pitpit-php-diff)
```

PHPackages © 2026

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