note 104508 added to function.spl-object-hash

From: Date: Sun, 19 Jun 2011 10:57:31 +0000
Subject: note 104508 added to function.spl-object-hash
Groups: php.notes 
Request: Send a blank email to php-notes+get-180666@lists.php.net to get a copy of this message
if you don't like how spl_object_hash works, here is an alternative class AAA { protected $hash; function __construct() { $this->hash = function() { static $hashStr; if(!isset($hashStr)) $hashStr = uniqid(get_called_class(), true); return $hashStr; }; } function getHashCode() { $f = $this->hash; return $f(); } } i used a closure and a static variabile because storing hashcode as class field the == operator would not worked like expected HTH ---- Server IP: 69.147.83.197 Probable Submitter: 87.10.27.138 ---- Manual Page -- http://www.php.net/manual/en/function.spl-object-hash.php Edit -- https://master.php.net/note/edit/104508 Del: integrated -- https://master.php.net/note/delete/104508/integrated Del: useless -- https://master.php.net/note/delete/104508/useless Del: bad code -- https://master.php.net/note/delete/104508/bad+code Del: spam -- https://master.php.net/note/delete/104508/spam Del: non-english -- https://master.php.net/note/delete/104508/non-english Del: in docs -- https://master.php.net/note/delete/104508/in+docs Del: other reasons-- https://master.php.net/note/delete/104508 Reject -- https://master.php.net/note/reject/104508 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#180666) next »