The php Function spl_Object_Hash()
The php function spl_object_hash() takes an object and gives it a unique identifier. This can then be used as a key in an array or other data structure. It works in the same way as an address in C or an id in Python.
A hash is not equals or contains; it algorithmically reduces data to a scalar value. So a hash does not guarantee that two identical inputs will provide the same output. However, an object's hash can be used as a key to a data structure, and that means it is possible for the same object to appear twice in an array.
This is what makes spl_object_hash() useful. This function can take a string and return a lowercase hex number. It is a great way to make a key for an array.
It is also useful when serializing objects and unserializing them. Since the hex numbers are unique, the object can still be identified after it is recreated. This can be especially helpful in situations where multiple copies of an object must exist (like a response cache).
The function spl_object_id() does a similar job but it is older and it doesn't really provide any more information than spl_object_hash. The newer spl_object_hash() is more useful and it's probably worth migrating if you're using this function.
It is also important to note that this function is only useful if the objects are stored in the same order. Performing a containment check before calling attach() will not change the order of the object set. In fact, doing so will probably be redundant and expensive.