关于使用php的spl_object_hash生成GUID


转自: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.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值