Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104110 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 24724 invoked from network); 4 Feb 2019 14:05:51 -0000 Received: from unknown (HELO localhost.localdomain) (76.75.200.58) by pb1.pair.com with SMTP; 4 Feb 2019 14:05:51 -0000 To: internals@lists.php.net References: Date: Mon, 4 Feb 2019 11:46:42 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Posted-By: 46.193.65.172 Subject: Re: RFC Weakrefs From: ajf@ajf.me (Andrea Faulds) Message-ID: 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