Feature #37286

Feature #37276: Customizable ValueObject hash

Include object properties in Value Object hash creation

Added by Adrian Föder about 9 years ago. Updated about 9 years ago.

Status:
Closed
Priority:
Should have
Assignee:
Category:
Persistence
Start date:
2012-05-18
Due date:
% Done:

0%

Estimated time:
PHP Version:
Has patch:
No
Complexity:

Description

currently, the Value Object hash creation doesn't take arbitrary object properties into account (only DateTime properties at the moment).
PHP provides a spl_object_hash() method, we should check if this is possible to add.
I'll provide a Test.


Related issues

Related to TYPO3.Flow - Bug #37352: generateValueHash() should use getIdentifierByObject()Under ReviewKarsten Dambekalns2012-05-21

Actions
#1

Updated by Gerrit Code Review about 9 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/11285

#2

Updated by Adrian Föder about 9 years ago

OK, unfortunately two subsequent creations of the same objects produce a different spl_object_hash:

        $testObject1 = new $className();
        $testObject1->someInteger = 42;
        $testObject1->someString = 'Life, the Universe and Everything';

        $testObject2 = clone $testObject1;

        $this->assertSame(spl_object_hash($testObject1), spl_object_hash($testObject2));

results in

Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-00000000785be9f20000000040f79b70
+00000000785be9fc0000000040f79b70

Looking closer, this is intended/documented behavior (also I didn't get it from reading alone). So, it's not a "hash" like we know it from md5 or sha1, but furthermore a unique object ID.
Due to the fact we're talking about Value objects here, we need to determine whether an object's content will be the same.

Any further suggestions for this?

#3

Updated by Karsten Dambekalns about 9 years ago

  • The value object hash is built from the constructor arguments.
  • Value objects are immutable.
  • Thus the hash never needs to change.

The only thing missing is support for entities not using FLOW3_Persistence_Identifier as identifier.

#4

Updated by Karsten Dambekalns about 9 years ago

  • Status changed from Under Review to Closed

See #37352.

Also available in: Atom PDF