ThinkPHP源码学习 to_guid_string函数 根据PHP各种类型变量生成唯一标识号
/**
* 根据PHP各种类型变量生成唯一标识号
* @param mixed $mix 变量
* @return string
*/
functionto_guid_string($mix){if(is_object($mix)){returnspl_object_hash($mix);//spl_object_hash—返回指定对象的hashid}elseif(is_resource($mix)){//is_resource—检测变量是否为资源类型$mix=get_resource_type($mix).strval($mix);//get_resource_type—返回资源(resource)类型//strval—获取变量的字符串值}else{$mix=serialize($mix);//serialize—产生一个可存储的值的表示//$name="津沙港湾"serialize系列化为s:12:"津沙港湾";}returnmd5($mix);//md5—计算字符串的MD5散列值}classStudent{public$name='津沙港湾';}$stu=newStudent();//对象$fp=fopen("d:/wamp/counter.txt","w");//资源$name="津沙港湾";//字符串echoto_guid_string($stu);echo"<br/>";echoto_guid_string($fp);echo"<br/>";echoto_guid_string($name);
运行结果为:
00000000411ac22f0000000001dac5a4
7c8337ca66fc7eb79d20461b44630219
99a71c3a715645befef323c9a805f662
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。