Skip to content

fix: numeric string arrays incorrectly treated as identical#95

Merged
jfcherng merged 1 commit into
jfcherng:v7from
DKhalil:fix/numeric-string-comparison
Jun 22, 2026
Merged

fix: numeric string arrays incorrectly treated as identical#95
jfcherng merged 1 commit into
jfcherng:v7from
DKhalil:fix/numeric-string-comparison

Conversation

@DKhalil

@DKhalil DKhalil commented Jun 22, 2026

Copy link
Copy Markdown

PHP 8's <=> compares numeric string arrays numerically, so ['00'] <=> ['0'] returns 0. The renderer sees this as "identical" and returns empty output.

Fix: check === first for equality, only use <=> for ordering. Force non-zero when arrays differ but spaceship says otherwise.

Reproducer:

DiffHelper::calculate('00', '0', 'SideBySide'); // returns '' instead of a diff
DiffHelper::calculate('1', '01', 'SideBySide'); // same issue

Fixes #94

PHP 8's <=> operator compares numeric string arrays using numeric
semantics, causing "00" and "0" (or "1" and "01", "10" and "1e1") to
be treated as identical. This made the renderer short-circuit and
return empty output for inputs that differ only in numeric
string representation.

Use === for the equality check and fall back to <=> only for ordering,
forcing a non-zero result when arrays are strictly different.
@jfcherng

Copy link
Copy Markdown
Owner

Thanks alot :D

@jfcherng jfcherng changed the title Fix: numeric string arrays incorrectly treated as identical fix: numeric string arrays incorrectly treated as identical Jun 22, 2026
@jfcherng jfcherng merged commit 69a96a5 into jfcherng:v7 Jun 22, 2026
5 checks passed
jfcherng pushed a commit that referenced this pull request Jun 22, 2026
Signed-off-by: Jack Cherng <jfcherng@gmail.com>
@DKhalil DKhalil deleted the fix/numeric-string-comparison branch June 22, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zero comparison will result in an empty diff

2 participants