As others have noted, this function now returns the ID, padded with zeroes.
It does not produce a cryptographic hash (which is not what the name hints at, either), nor does it hide it which order the objects were created.
If you wish to give your objects unique identifiers while hiding in which order they were created, you can achieve this by hashing their ID together with other predictable values:
<?php
function objectHash(object $object): string
{
return hash('sha512', $object::class . spl_object_id($object));
}
?>
Here's an example usage:
<?php
class Person
{
function __construct(public string $name) {}
}
$anna = new Person('Anna');
$bob = new Person('Bob');
var_export(objectHash($anna)); echo "\n";
var_export(objectHash($bob)); ?>
Feel free to choose another hash, or hash other values along with their ID, for it to better suit your environment.