note 110863 added to splobjectstorage.gethash
| From: | aron dot duby at gmail dot com | Date: | Mon, 17 Dec 2012 07:09:09 +0000 |
| Subject: | note 110863 added to splobjectstorage.gethash | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-192556@lists.php.net to get a copy of this message | ||
This also appears to be the function which gets used within the contains() function, so if all the
objects you are storing already have a unique id you can overwrite this function with your own
class.
<?php
class UserStorage extends SPLObjectStorage{
public function getHash($obj){
return $obj->id;
}
}
$us = new UserStorage();
$user1 = new User(1);
$user2 = new User(2);
$us->attach($user1);
$us->attach($user2);
$me = new User(2);
// the following would normally fail since they are two separate objects
// but it works now with our extended getHash()
$us->contains($me);
?>
----
Server IP: 69.147.83.199
Probable Submitter: 108.239.48.149
----
Manual Page -- http://php.net/manual/en/splobjectstorage.gethash.php
Edit -- https://master.php.net/note/edit/110863
Del: integrated -- https://master.php.net/note/delete/110863/integrated
Del: useless -- https://master.php.net/note/delete/110863/useless
Del: bad code -- https://master.php.net/note/delete/110863/bad+code
Del: spam -- https://master.php.net/note/delete/110863/spam
Del: non-english -- https://master.php.net/note/delete/110863/non-english
Del: in docs -- https://master.php.net/note/delete/110863/in+docs
Del: other reasons-- https://master.php.net/note/delete/110863
Reject -- https://master.php.net/note/reject/110863
Search -- https://master.php.net/manage/user-notes.php