ThinkPHP源碼學習 to_guid_string函數 根據PHP各種類型變數產生唯一標識號

來源:互聯網
上載者:User

標籤:thinkphp源碼學習 to_guid_string函數 hash md5

/**
 * 根據PHP各種類型變數產生唯一標識號
 * @param mixed $mix 變數
 * @return string
 */

function to_guid_string($mix) {    if (is_object($mix)) {        return spl_object_hash($mix);//spl_object_hash — 返回指定對象的hash id     } 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:"津沙港灣";    }    return md5($mix);//md5 — 計算字串的 MD5 散列值}class Student{    public $name=‘津沙港灣‘;}$stu=new Student();//對象$fp = fopen("d:/wamp/counter.txt","w");//資源$name="津沙港灣";//字串echo to_guid_string($stu);echo "<br/>";echo to_guid_string($fp);echo "<br/>";echo to_guid_string($name);


運行結果為:

00000000411ac22f0000000001dac5a4
7c8337ca66fc7eb79d20461b44630219
99a71c3a715645befef323c9a805f662

本文出自 “11400485” 部落格,請務必保留此出處http://11410485.blog.51cto.com/11400485/1833446

ThinkPHP源碼學習 to_guid_string函數 根據PHP各種類型變數產生唯一標識號

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.