Here is why you should avoid using spl_object_hash() in PHP
from the documentation: "This function returns a unique identifier for the object. This id can be used as a hash key for storing objects or for identifying an object."
spl_object_hash() actually returns an md5 hash of the internal pointer of an object.
PHP efficiently reuses internal pointers; meaning the second you remove an object the pointer is reused.
thus:
<?php
$transaction_ids = array();
for( $i=0; $i<10; $i++ ) {
$transaction = (object)('transaction ' . $i);
$hash = spl_object_hash( $transaction );
$transaction_ids[] = $hash;
}
print_r( $transaction_ids );
?>
will output:
Array ( [0] => 4b8051a089b9e8352a97af234d4478a7 [1] => 076b44c4ffe009b98c0ba3348459c57a [2] => 4b8051a089b9e8352a97af234d4478a7 [3] => 076b44c4ffe009b98c0ba3348459c57a [4] => 4b8051a089b9e8352a97af234d4478a7 [5] => 076b44c4ffe009b98c0ba3348459c57a [6] => 4b8051a089b9e8352a97af234d4478a7 [7] => 076b44c4ffe009b98c0ba3348459c57a [8] => 4b8051a089b9e8352a97af234d4478a7 [9] => 076b44c4ffe009b98c0ba3348459c57a )
not even remotely unique, could lead to serious problems, and simply.. I'd forget using it if I was you.














If you need unique IDs consider adding microtime() to the hash ;-)