note 91164 added to function.spl-object-hash

From: Date: Thu, 28 May 2009 10:12:23 +0000
Subject: note 91164 added to function.spl-object-hash
Groups: php.notes 
Request: Send a blank email to php-notes+get-156100@lists.php.net to get a copy of this message
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. ---- Server IP: 212.24.129.51 Probable Submitter: 86.49.10.239 ---- Manual Page -- http://www.php.net/manual/en/function.spl-object-hash.php Edit -- https://master.php.net/note/edit/91164 Del: integrated -- https://master.php.net/note/delete/91164/integrated Del: useless -- https://master.php.net/note/delete/91164/useless Del: bad code -- https://master.php.net/note/delete/91164/bad+code Del: spam -- https://master.php.net/note/delete/91164/spam Del: non-english -- https://master.php.net/note/delete/91164/non-english Del: in docs -- https://master.php.net/note/delete/91164/in+docs Del: other reasons-- https://master.php.net/note/delete/91164 Reject -- https://master.php.net/note/reject/91164 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#156100) next »