转自:http://php.net/manual/zh/function.spl-object-hash.php
The follow function is a implementation of the PHP´s function spl_object_hash(), unavailable in versions less 5.2.0.
But, the algorithm of this function is different of the original PHP´s function.
(Sorry... my english is very bad...)
<?php
if (!function_exists('spl_object_hash')) {
/**
* Returns the hash of the unique identifier for the object.
*
* @param object $object Object
* @author Rafael M. Salvioni
* @return string
*/
function spl_object_hash($object)
{
if (is_object($object)) {
ob_start(); var_dump($object); $dump = ob_get_contents(); ob_end_clean();
if (preg_match('/^object\(([a-z0-9_]+)\)\#(\d)+/i', $dump, $match)) {
return md5($match[1] . $match[2]);
}
}
trigger_error(__FUNCTION__ . "() expects parameter 1 to be object", E_USER_WARNING);
return null;
}
}
?>
Note:
When an object is destroyed, its hash may be reused for other objects.