您的位置:首页 > 移动开发 > Objective-C

关于使用php的spl_object_hash生成GUID

2014-08-22 13:51 537 查看
转自: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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: