Re: [VOTE] Weak References
| From: | Etienne Kneuss | Date: | Sat, 03 Sep 2011 16:29:50 +0000 |
| Subject: | Re: [VOTE] Weak References | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-55159@lists.php.net to get a copy of this message | ||
Hi,
On Sat, Sep 3, 2011 at 17:14, Lars Schultz <lars.schultz@toolpark.com>wrote:
> Am 03.09.2011 13:56, schrieb Etienne Kneuss:
>
>> Indeed, I planned to implement that as well, I haven't had the time to do
>> it
>>
>> yet though. It should happen in the following weeks.
>>
>
> Not to keep you from doing this...but couldn't that easily be solved by
> using a simple associative php array like this:
>
> $pseudoWeakMap = array();
> $pseudoWeakMap[spl_object_**hash($obj)] = new WeakReference($obj);
>
> or did I misunderstand the concept? I hope I'll have a chance to use
> WeakReferences soon in my project;)
>
>
My understanding of weak maps would be a way to associate data with objects,
and have the data be freed once the object itself is deleted.
So basically in example:
$map = new WeakMap;
$obj = new Class;
$map[$obj] = .. some data ..
...
var_dump($map[$obj]); // .. some data ..
unset($obj); // unsets $map[$obj] automatically as well.
var_dump(isset($map[$obj])); // bool(false)
So sure, it could be implemented using spl_object_hash and having the Class
destructor take care of deleting all that associated Data, but using
weakmaps would make it far more convenient.
Best,
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Etienne Kneuss
http://www.colder.ch