sebastian/diff is a PHP library that generates and parses unified diff output.
The library solves the problem of programmatically comparing two strings and representing their differences in a human-readable format. It provides the Differ class to generate textual diffs and the Parser class to parse unified diff format back into an object graph. The tool supports multiple output formats: UnifiedDiffOutputBuilder for standard unified diff output used by PHPUnit, StrictUnifiedDiffOutputBuilder for strict unified diff format compatible with patch and git apply, and DiffOnlyOutputBuilder for output containing only differing lines. Developers can also implement the DiffOutputBuilderInterface to generate custom output formats.
This library is well-suited for projects that need to display or analyze code changes, such as testing frameworks, version control tools, or code review systems. It works as a standalone component, having been factored out of PHPUnit into a reusable dependency. Projects should add it as a development-time dependency if diff generation is only needed during testing or development workflows.
The project maintains a focused scope on diff generation and parsing without attempting to provide broader version control functionality. Development activity shows consistent maintenance with regular updates addressing edge cases and output format requirements. The codebase demonstrates attention to compatibility with standard Unix diff tools and Git workflows through its strict unified diff output builder. The project accepts contributions that extend output format options while preserving backward compatibility with existing implementations.