Skip to content

Conversation

@ccurdt
Copy link

@ccurdt ccurdt commented Jul 9, 2025

Patch Summary

This patch improves the value comparison logic in Doctrine’s UnitOfWork class during change detection.

Key Changes

  • Introduces a private method valuesAreEqual() that compares values with special handling for:

    • null values,
    • DateTimeInterface instances using the spaceship operator (<=>),
    • arrays recursively, checking keys and values,
    • and falls back to strict comparison (===) for other types.
  • Replaces existing strict equality checks with valuesAreEqual() to prevent false positives.

Benefit

Enhances reliability in detecting changes for entities with DateTime and array fields.

ccurdt added 2 commits July 9, 2025 11:17
- Introduced a new private method `valuesAreEqual` in UnitOfWork to perform value comparisons.
- This method correctly compares null values, DateTimeInterface instances (using the spaceship operator),
  and arrays recursively to ensure deep equality.
- Replaced existing strict equality checks (===) with `valuesAreEqual` in change detection logic.
- Added recursive array comparison method `arraysAreEqual` to verify keys and values match exactly.
- These changes prevent false positives in Doctrine change tracking caused by naive comparisons.
- Improves accuracy and stability in detecting entity changes, especially for date and array fields.
@gseidel
Copy link
Contributor

gseidel commented Aug 21, 2025

May you provide some test, where the uow doesn't detect changes or it detect changes that aren't changes and that are covered by your code now?

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.

2 participants