Skip to content
PHP Ecosystem
Explore

DifferInterface

API reference › Diff › DifferInterface

interfacePHPForge\Diff\DifferInterface
Sourcesrc/DifferInterface.php
Implemented by 1 type

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

Implementations split both inputs on "\n" with explode(), 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), removed from the old input (DiffOp::Remove) or added from the new input (DiffOp::Add).

MethodDescriptionDefined by
diff() abstractReturns the edit script that transforms $old into $new.DifferInterface
abstract public function diff(string $old, string $new): list<PHPForge\Diff\DiffLine>

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

Parameters

ParameterTypeDescription
$oldstringOriginal input, split into lines on "\n".
$newstringTarget input, split into lines on "\n".

Returns

list<DiffLine>: 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.