Optionally detect changes in PHP objects by value, not reference #6949

Open
opened 2026-01-22 15:42:01 +01:00 by admin · 0 comments
Owner

Originally created by @michnovka on GitHub (Mar 11, 2022).

Feature Request

After reading docs about DateTime object in Doctrine, I got an idea for an improvement.

Lets allow objects to be compared by value for custom types

Q A
New Feature yes
RFC no
BC Break no

Summary

My idea is to provide interface

interface DoctrineValueComparable
{
    function compareByValue(): int;
}

When evaluating changed columns in UnitOfWork, we could do:

if ($value instanceof DoctrineValueComparable)
{
    $isChanged = $value->compareByValue($newValue) !== 0;
}

This would allow e.g. to define custom DateTime type which would implement this interface and company by unix timestamp. Thus updating the instance of DateTime directly WOULD have an effect.

Originally created by @michnovka on GitHub (Mar 11, 2022). ### Feature Request After reading [docs about DateTime](https://www.doctrine-project.org/projects/doctrine-orm/en/2.11/cookbook/working-with-datetime.html) object in Doctrine, I got an idea for an improvement. Lets allow objects to be compared by value for custom types | Q | A |------------ | ------ | New Feature | yes | RFC | no | BC Break | no #### Summary My idea is to provide interface ```php interface DoctrineValueComparable { function compareByValue(): int; } ``` When evaluating changed columns in `UnitOfWork`, we could do: ```php if ($value instanceof DoctrineValueComparable) { $isChanged = $value->compareByValue($newValue) !== 0; } ``` This would allow e.g. to define custom `DateTime` type which would implement this interface and company by unix timestamp. Thus updating the instance of `DateTime` directly WOULD have an effect.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6949