Don't make the same error as me. The address of the object may be different while the object IS the same (i.e spl_object_hash returns the same id for both objects).
For instance, I wrote this test:
$a = $b = new StdClass;
$objects = [$a, $b];
var_dump(spl_object_hash($a), spl_object_hash($b));
foreach ($objects as $object1);
var_dump(spl_object_hash($a), spl_object_hash($b));
foreach ($objects as &$object2);
var_dump(spl_object_hash($a), spl_object_hash($b));
As expected, the id returned by spl_object_hash() is the same of $a, $b and the objects in $objects. But the address of the objects in $objects are not the same as $a and $b:
string(32) "000000007fbf1856000000002722d91d"
string(32) "000000007fbf1856000000002722d91d"
string(32) "000000007fbf1856000000002722d91d"
string(32) "000000007fbf1856000000002722d91d"
string(32) "000000007fbf1856000000002722d91d"
string(32) "000000007fbf1856000000002722d91d"
Apparently modern xdebug (2.4.0+) removed the ability to see memory addresses https://youtrack.jetbrains.com/issue/WI-33581
– allejo – 2019-12-03T07:27:26.417