note 91164 deleted from function.spl-object-hash by googleguy
| From: | googleguy@php.net | Date: | Mon, 08 Oct 2012 04:11:13 +0000 |
| Subject: | note 91164 deleted from function.spl-object-hash by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191176@lists.php.net to get a copy of this message | ||
Note Submitter: SlappyTheFish
----
With regards to the previous post, I'm not entirely sure that easy does do it. Consider the
following code:
<?php
class Testy
{
public $something;
public function __toString()
{
return serialize($this);
}
}
$objOne = new Testy();
$objOne->something = "hello";
$objTwo = new Testy();
$objTwo->something = "hello";
printf("objOne:\n");
printf("Bad way: %s\n", md5((string)$objOne));
printf("SPL Way: %s\n", spl_object_hash($objOne));
printf("objTwo:\n");
printf("Bad way: %s\n", md5((string)$objTwo));
printf("SPL Way: %s\n", spl_object_hash($objTwo));
?>
The spl_object_hash function returns a hash based on the particular object, not the content. The
spl hash will always be the same for a given object, regardless of content.