Feature #37286

Feature #37276: Customizable ValueObject hash

Include object properties in Value Object hash creation

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

Should have
Start date:
Due date:
% Done:


Estimated time:
PHP Version:
Has patch:


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


Updated by Gerrit Code Review over 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


Updated by Adrian Föder over 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
@@ @@

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?


Updated by Karsten Dambekalns over 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.


Updated by Karsten Dambekalns over 9 years ago

  • Status changed from Under Review to Closed

See #37352.

Also available in: Atom PDF