Feature #37276: Customizable ValueObject hash
Include object properties in Value Object hash creation
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.
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));
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?