Hi, On Sat, Sep 3, 2011 at 17:14, Lars Schultz <lars.schu...@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