Hi Joe,
I like the idea of adding weak references to the PHP core (as opposed to
PECL), so I'm generally in favour of this RFC. This type of feature
which the engine must be aware of should be maintained as part of it —
and it not requiring a PECL extension means it can actually be used by
much more code.
Have you considered adding a WeakMap type as well — a map of (object)
keys to values where the keys are weakly referenced? This is a useful
construct based on weak references and something I'm sure will be
wanted. It could in theory be implemented in userland on top of your
proposal, but it would be nice to save userland having to reimplement it
(probably multiple times), and userland could be saved the problem of
manually cleaning up now-dead weak references (annoyingly O(n)) and
deciding when to do so — an internal implementation can handle it
automagically and more performantly. :)
I do predict one potentially annoying part of implementing a WeakMap
though: you could insert a value which has a destructor and then observe
when keys are destructed. But it's not like destructors are a new
problem in PHP.
Thanks,
Andrea
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php