php-diff icon indicating copy to clipboard operation
php-diff copied to clipboard

ATTENTION! Don't use this package and any forks, use sebastian/diff instead

Open gugglegum opened this issue 6 years ago • 6 comments

This package (chrisboulton/php-diff) is abandoned and not supported for several years. There's 167 other packages that forked from this root repo, but they are ugly. Most of them doesn't contain any changes. Many other contain questionable changes. A small number of forks contains 1-2 fixes or addition of some functionality necessary to authors. But all these forks are very low quality. Most of forks (as of original repo) doesn't use namespaces which makes difficulties if you want to use Composer's autoloader. There is a few repos that adds namespaces, but they seems to be abandoned too. They mostly are missing "Issues" section, so nobody can report a bug. Code quality is not good enough (at least for me). No unit-tests, no docs, no UTF-8 support. And all forks are crashes with count(): Parameter must be an array or an object that implements Countable when you making a diff for two arrays where one of them is empty. The error is in lib/Diff/SequenceMatcher.php in setSeq1() and setSeq2() (need replace if($a == $this->a) { to if($a === $this->a) {). This is very simple bug, but nobody found it and fixed.

I've tried these packages:

  1. chrisboulton/php-diff -- no namespaces, no multi-byte encodings
  2. phpspec/php-diff -- fixed some bugs, possible added multi-byte encodings, but still not namespaces, no Issues section
  3. adaptivemedia/php-text-difference -- added namespaces, but no Issues section, no Composer package, dev-stability
  4. JBlond/php-diff -- looks like supported, has Issues section, but no namespaces...

Then I found a better alternative of all this misunderstanding -- it's sebastian/diff (https://github.com/sebastianbergmann/diff). It works little different, but it has much better code quality, actively maintaining, supported and the author is an authority in PHP world (he maintain PHPUnit). Actually previously it was a part of PHPUnit but then was factored out. So I recommend to use his package instead and forget about chrisboulton/php-diff and all its forks.

gugglegum avatar Aug 09 '18 19:08 gugglegum

@gugglegum PRs are welcomed 👍 and yes I work on it as needed.

JBlond avatar Dec 07 '18 12:12 JBlond

@gugglegum JBlond/php-diff has now namespaces

JBlond avatar Jan 14 '19 11:01 JBlond

I have my changes. https://github.com/jfcherng/php-diff

  • Various bug fixes and performance rewrites.
  • Published on Composer. (jfcherng/php-diff)
  • UTF-8-ready.
  • Adapt semver 2. (i.e., version number = major.minor.patch)
  • Follow PSR-1, PSR-4, PSR-12.
  • Utilize PHP 7.1 features and make it type-hinted. (PHP >= 7.1 for 6.10.x releases and PHP >= 7.4 for the latest release)
  • Add Combined, JsonText and JsonHtml renderers.
  • Add none-level, char-level and word-level detailed diff for HTML renderers.
  • Add classes DiffHelper and RendererFactory for simpler usage.
  • Add multi-language support (English, Chinese, etc...) for renderers.
  • Add ability to output colored cli diff output.

jfcherng avatar Jan 17 '19 22:01 jfcherng

@JBlond I see you still develop php-diff recently. Maybe you would be interested in my repo above too.

jfcherng avatar Feb 19 '19 09:02 jfcherng

sebastian/diff doesn't seem to have colorized html output, and it shows the differences only as lines. It may be ok for code, but not for highlighting the differences in blocks of text, for example revisions of a blog post (if only a word in a sentence is changed, I want to see only that word highlighted). Anybody knows a better library to have something similar to diffchecker.com ?

Edit: jfcherng/php-diff works very well, thanks :)

fmonts avatar Oct 18 '20 11:10 fmonts

@fmonts check out JBlond/php-diff ,too

JBlond avatar Oct 18 '20 12:10 JBlond