propelorm / Propel2

Propel2 is an open-source high-performance Object-Relational Mapping (ORM) for modern PHP
http://propelorm.org/
MIT License
1.26k stars 399 forks source link

Use object-equality instead of reference-equality to compare object properties #1776

Closed nederdirk closed 3 years ago

nederdirk commented 3 years ago

Sometimes we use boxed primitives for types that have more specific semantics than just string or int. This allows us to define methods on the boxed primitives, enabling greater class coherence.

However, entities with boxed primitives are always reported as 'does not have only default values', because the hasOnlyDefaultValues function uses !==. Generally this is a good idea, but for objects this compares the references instead of the contents.

This patch inspects the default-value initialiser for 'starts with new', as a proxy for 'is this an object type'.

There's a test to validate this behaviour. I validated that the test fails with the unpatched ObjectBuilder code.