PHPackages                             facebook/difflib - 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. facebook/difflib

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

facebook/difflib
================

v1.3.0(4y ago)11625.7k↓42%8[3 issues](https://github.com/hhvm/difflib/issues)10MITHack

Since Sep 5Pushed 4y ago22 watchersCompare

[ Source](https://github.com/hhvm/difflib)[ Packagist](https://packagist.org/packages/facebook/difflib)[ RSS](/packages/facebook-difflib/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (6)Versions (9)Used By (10)

DiffLib
=======

[](#difflib)

[![Continuous Integration](https://github.com/hhvm/difflib/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/hhvm/difflib/actions/workflows/build-and-test.yml)

DiffLib is a Hack library for creating and parsing diffs. Diffs can be created between any two sequences of items. Additional helpers (such as support for unified diffs, and colored diffs) are provided for string diffs.

Diffs are represented as a sequence of `DiffOp` operations; these can 'keep' an element (i.e. it's unchanged in both sequences), insert an element, or delete an element. For example, in a unified diff, these would be:

```
 DiffKeepOp
-DiffDeleteOp
+DiffInsertOp
```

String diffs are typically represented as a sequence of lines, but can also be represented as a sequence of characters, allowing intra-line diffs.

Diff output formats
-------------------

[](#diff-output-formats)

difflib can create standard unified diffs:

[![@@ -1 +1@@ -Foo Bat Baz +Foo Bar Baz](udiff.png)](udiff.png)

difflib can also create colored diffs, with intra-line edits highlighted:

[![same diff as above, but with 'Bat' highlighted red, 'Bar' highlighted green](clidiff.png)](clidiff.png)

A concrete implementation is provided for standard CLI terminals, and an abstract base class for other implementations, such as HTML or XHP.

Examples
--------

[](#examples)

```
use namespace Facebook\DiffLib;

function create_unified_diff(string $from, string $to): string {
  return DiffLib\StringDiff::lines($from, $to)->getUnifiedDiff();
}

function create_colored_diff(string $from, string $to): string {
  return DiffLib\CLIColoredUnifiedDiff::create($from, $to);
}

final class IntDiff extends DiffLib\Diff {
  const type TContent = int;
}

function dump_int_diff(vec $from, vec $to): void {
  $diff = (new IntDiff($from, $to))->getDiff();
  foreach ($diff as $op) {
    if ($op is DiffLib\DiffKeepOp) {
      \printf("  %d\n", $op->getContent());
    } else if ($op is DiffLib\DiffDeleteOp) {
      \printf("- %d\n", $op->getContent());
    } else {
      $op = $op as DiffLib\DiffInsertOp;
      printf("+ %d\n", $op->getContent());
    }
  }
}
```

`dump_int_diff(vec[1, 3, 9], vec[1, 4, 9])` will produce this output:

```
  1
- 3
+ 4
  9

```

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

[](#requirements)

- The current release version of HHVM

Installing DiffLib
------------------

[](#installing-difflib)

```
composer require facebook/difflib

```

How DiffLib works
-----------------

[](#how-difflib-works)

Diffs are created using Myers' diff algorithm: Myers, E.W. Algorithmica (1986) 1: 251.

For more details, see [the commented implementation](src/Diff.php).

Full documentation
------------------

[](#full-documentation)

- `DiffLib\Diff`: abstract base class. Needs to be subclassed to operate on any particular type.
- `DiffLib\StringDiff`: final class for diffing strings, and adds support for creating unified diffs
- `DiffLib\ColoredUnifiedDiff`: abstract class for rendering unified diffs. Output may be any type - for example, strings or XHP.
- `DiffLib\CLIColoredUnifiedDiff`: abstract final class for rendering unified diffs to a terminal that supports color escape sequences. Provides intra-line highlighting.
- `DiffLib\DiffOp`: abstract class for a diff operation. Sealed to `DiffInsertOp`, `DiffKeepOp`, and `DiffDeleteOp`.
- `DiffLib\cluster()`: utility function to group together sequential operations of the same kind. Converts `vec` to a generally shorter number of `vec`

License
-------

[](#license)

DiffLib is MIT licensed, as found in the LICENSE file.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community35

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 55.2% 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 ~159 days

Recently: every ~240 days

Total

8

Last Release

1694d ago

Major Versions

v0.2 → v1.02018-09-24

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3757713?v=4)[Joel Marcey](/maintainers/JoelMarcey)[@JoelMarcey](https://github.com/JoelMarcey)

![](https://avatars.githubusercontent.com/u/8306375?v=4)[HHVM Community Bot](/maintainers/hhvm-bot)[@hhvm-bot](https://github.com/hhvm-bot)

![](https://avatars.githubusercontent.com/u/601530?v=4)[Yang, Bo](/maintainers/Atry)[@Atry](https://github.com/Atry)

![](https://avatars.githubusercontent.com/u/727402?v=4)[Alexey Toptygin](/maintainers/alexeyt)[@alexeyt](https://github.com/alexeyt)

---

Top Contributors

[![fredemmott](https://avatars.githubusercontent.com/u/360927?v=4)](https://github.com/fredemmott "fredemmott (32 commits)")[![jjergus](https://avatars.githubusercontent.com/u/2483917?v=4)](https://github.com/jjergus "jjergus (9 commits)")[![DavidSnider](https://avatars.githubusercontent.com/u/10112104?v=4)](https://github.com/DavidSnider "DavidSnider (4 commits)")[![lexidor](https://avatars.githubusercontent.com/u/31805625?v=4)](https://github.com/lexidor "lexidor (4 commits)")[![zpao](https://avatars.githubusercontent.com/u/8445?v=4)](https://github.com/zpao "zpao (2 commits)")[![yns88](https://avatars.githubusercontent.com/u/757922?v=4)](https://github.com/yns88 "yns88 (1 commits)")[![bigfootjon](https://avatars.githubusercontent.com/u/6403568?v=4)](https://github.com/bigfootjon "bigfootjon (1 commits)")[![zzagorsk-fb](https://avatars.githubusercontent.com/u/20444420?v=4)](https://github.com/zzagorsk-fb "zzagorsk-fb (1 commits)")[![kmeht](https://avatars.githubusercontent.com/u/1120478?v=4)](https://github.com/kmeht "kmeht (1 commits)")[![periodic1236](https://avatars.githubusercontent.com/u/1748071?v=4)](https://github.com/periodic1236 "periodic1236 (1 commits)")[![Wilfred](https://avatars.githubusercontent.com/u/70800?v=4)](https://github.com/Wilfred "Wilfred (1 commits)")[![WizKid](https://avatars.githubusercontent.com/u/59419?v=4)](https://github.com/WizKid "WizKid (1 commits)")

### Embed Badge

![Health badge](/badges/facebook-difflib/health.svg)

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

###  Alternatives

[hhvm/hsl

The Hack Standard Library

1151.1M55](/packages/hhvm-hsl)

PHPackages © 2026

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