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

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

philiprehberger/php-diff
========================

Diff strings, arrays, and objects with unified, HTML, and structured output

v1.0.4(1mo ago)11[1 PRs](https://github.com/philiprehberger/php-diff/pulls)MITPHPPHP ^8.2CI passing

Since Mar 15Pushed 1mo agoCompare

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

READMEChangelogDependencies (3)Versions (6)Used By (0)

PHP Diff
========

[](#php-diff)

[![Tests](https://github.com/philiprehberger/php-diff/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/php-diff/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/892eb7325f6164e3de65073eda2b1703bc2761b4b88539dd18f17d2a5d38ed1b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f7068702d646966662e737667)](https://packagist.org/packages/philiprehberger/php-diff)[![License](https://camo.githubusercontent.com/b2ddd90298babaf46315deb6ea366811bbe624ac9d832902420b0d8a77abd0be/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7068696c69707265686265726765722f7068702d64696666)](LICENSE)

Diff strings, arrays, and objects with unified, HTML, and structured output.

Requirements
------------

[](#requirements)

- PHP 8.2+

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

[](#installation)

```
composer require philiprehberger/php-diff
```

Usage
-----

[](#usage)

### Comparing Strings

[](#comparing-strings)

```
use PhilipRehberger\Diff\Diff;

$diff = Diff::strings("hello\nworld", "hello\nphp");

$diff->hasChanges();    // true
$diff->toUnified();     // unified diff string
$diff->toHtml();        // HTML with / tags
$diff->toArray();       // array of DiffLine objects
$diff->stats();         // DiffStats { added: 1, removed: 1, unchanged: 1 }
```

### Comparing Arrays

[](#comparing-arrays)

```
use PhilipRehberger\Diff\Diff;

$diff = Diff::arrays(
    ['name' => 'Alice', 'age' => 30, 'city' => 'NYC'],
    ['name' => 'Alice', 'age' => 31, 'country' => 'US'],
);

$diff->hasChanges();  // true
$diff->changes();     // all Change objects
$diff->added();       // entries only in the new array
$diff->removed();     // entries only in the old array
$diff->changed();     // entries with different values
```

### Comparing Objects

[](#comparing-objects)

```
use PhilipRehberger\Diff\Diff;

$old = (object) ['name' => 'Alice', 'age' => 30];
$new = (object) ['name' => 'Alice', 'age' => 31];

$diff = Diff::objects($old, $new);

$diff->hasChanges();  // true
$diff->changes();     // [PropertyChange { property: 'age', from: 30, to: 31 }]
```

API
---

[](#api)

### `Diff` (Static Entry Point)

[](#diff-static-entry-point)

MethodReturnsDescription`Diff::strings(string $old, string $new)``StringDiff`Compare two strings line by line`Diff::arrays(array $old, array $new)``ArrayDiff`Compare two arrays by key`Diff::objects(object $old, object $new)``ObjectDiff`Compare two objects by property### `StringDiff`

[](#stringdiff)

MethodReturnsDescription`toUnified(int $context = 3)``string`Unified diff format`toHtml()``string`HTML with ins/del tags`toArray()``array`Array of DiffLine value objects`hasChanges()``bool`Whether any differences exist`stats()``DiffStats`Count of added, removed, unchanged lines### `ArrayDiff`

[](#arraydiff)

MethodReturnsDescription`changes()``array`All changes`added()``array`Only added entries`removed()``array`Only removed entries`changed()``array`Only modified entries`hasChanges()``bool`Whether any differences exist### `ObjectDiff`

[](#objectdiff)

MethodReturnsDescription`changes()``array`All property changes`hasChanges()``bool`Whether any differences exist### Value Objects

[](#value-objects)

- **`DiffLine`** — `type` (`added`|`removed`|`unchanged`), `content`, `lineNumber`
- **`Change`** — `key`, `old`, `new`, `type` (`added`|`removed`|`changed`)
- **`PropertyChange`** — `property`, `from`, `to`
- **`DiffStats`** — `added`, `removed`, `unchanged`

Development
-----------

[](#development)

```
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
```

License
-------

[](#license)

MIT

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance90

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~1 days

Total

5

Last Release

49d ago

### Community

Maintainers

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

---

Top Contributors

[![philiprehberger](https://avatars.githubusercontent.com/u/8218077?v=4)](https://github.com/philiprehberger "philiprehberger (7 commits)")

---

Tags

phpdiffunified diffcomparemyershtml diff

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[jfcherng/php-diff

A comprehensive library for generating differences between two strings in multiple formats (unified, side by side HTML etc).

4705.1M51](/packages/jfcherng-php-diff)[localheinz/diff

Fork of sebastian/diff for use with ergebnis/composer-normalize

4637.0M5](/packages/localheinz-diff)[jblond/php-diff

A comprehensive library for generating differences between two hashable objects (strings or arrays).

36125.1k1](/packages/jblond-php-diff)[jbzoo/composer-diff

See what has changed after a composer update.

53888.9k1](/packages/jbzoo-composer-diff)[fisharebest/algorithm

Implementation of standard algorithms in PHP.

7192.7k1](/packages/fisharebest-algorithm)[phalcongelist/php-diff

A comprehensive library for generating differences between two hashable objects (strings or arrays).

12435.5k2](/packages/phalcongelist-php-diff)

PHPackages © 2026

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