Feature #37286
Feature #37276: Customizable ValueObject hash
Include object properties in Value Object hash creation
| Status: | Closed | Start date: | 2012-05-18 | |
|---|---|---|---|---|
| Priority: | Should have | Due date: | ||
| Assignee: | Adrian Föder | % Done: | 0% |
|
| Category: | Persistence | |||
| Target version: | TYPO3 Flow Base Distribution - 1.1 beta 2 | |||
| PHP Version: | Complexity: | |||
| Has patch: | No | |||
| Votes: | 0 |
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 Review | 2012-05-21 |
History
Updated by Gerrit Code Review about 1 year 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 12 months ago
OK, unfortunately two subsequent creations of the same objects produce a different spl_object_hash:
1 $testObject1 = new $className();
2 $testObject1->someInteger = 42;
3 $testObject1->someString = 'Life, the Universe and Everything';
4
5 $testObject2 = clone $testObject1;
6
7 $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?
Updated by Karsten Dambekalns 12 months 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.