# DifferInterface

> Computes a line-by-line edit script between two multi-line strings.

[API reference](/docs/api/index.md) › [Diff](/docs/extensions/diff/reference/index.md) › DifferInterface

| interface | `PHPForge\Diff\DifferInterface` |
| --- | --- |
| Source | [`src/DifferInterface.php`](https://github.com/php-forge/diff/blob/main/src/DifferInterface.php#L15) |

Implemented by 1 type:

- [`LineDiffer`](/docs/extensions/diff/reference/linediffer/index.md)

Computes a line-by-line edit script between two multi-line strings.

Implementations split both inputs on `"\n"` with [`explode()`](https://www.php.net/manual/en/function.explode.php), so an empty string is one empty line and a
trailing newline yields a trailing empty line. Every input line appears exactly once in the returned script, tagged
as kept ([`DiffOp::Context`](/docs/extensions/diff/reference/diffop/index.md#case-Context)), removed from the old input ([`DiffOp::Remove`](/docs/extensions/diff/reference/diffop/index.md#case-Remove)) or added from the new input
([`DiffOp::Add`](/docs/extensions/diff/reference/diffop/index.md#case-Add)).

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`diff()`](#method-diff) abstract | Returns the edit script that transforms `$old` into `$new`. | `DifferInterface` |

## Method details

### diff() <span id="method-diff"></span>

```php
abstract public function diff(string $old, string $new): list<PHPForge\Diff\DiffLine>
```

Returns the edit script that transforms `$old` into `$new`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$old` | `string` | Original input, split into lines on `"\n"`. |
| `$new` | `string` | Target input, split into lines on `"\n"`. |

**Returns**

`list<`[`DiffLine`](/docs/extensions/diff/reference/diffline/index.md)`>`: Edit script; its `Context` and `Remove` lines in order reproduce the lines of `$old`, and its `Context` and `Add` lines in order reproduce the lines of `$new`.