我对PHP SPL功能spl_object_hash感到困惑

时间:2018-09-18 08:00:44

标签: object hash spl

带有SPL函数“ spl_object_hash”的PHP演示代码如下所示:

<?php
class User
{
    public $id = '';
    public $name = '';

    public function __construct($name = '')
    {
        $this->name = $name;
        $this->id = spl_object_hash($this);
    }
}

$user1 = new User('blogdaren');
$user2 = new User('blogdaren');

$t1 = spl_object_hash(new User('blogdaren'));
$t2 = spl_object_hash(new User('blogdaren'));

var_dump($user1->id, $user2->id, $user1->id === $user2->id, $t1, $t2, $t1 === $t2);

我的困惑是:

  

$ user1-> id!== $ user2-> id ,看来效果不错。

     

$ t === $ t2 ,似乎值相同,为什么?

0 个答案:

没有答案
相关问题