Re: [PECL-DEV] Pecl proposal: weakreference_bc: Polyfilling WeakReference/WeakMap classes in php 7.1-7.4

[email protected] (Rowan Tommins) Sun, 5 Dec 2021 14:13:22 +0000
Newsgroups php.pecl.dev
Message-ID <[email protected]>
On 04/12/2021 23:13, tyson andre wrote:
> https://wiki.php.net/rfc/deprecate_dynamic_properties  recently passed, recommending using WeakMap for use cases
> where extra information needs to be associated with an object instance that isn't owned.

> However, WeakMap is new in PHP 8.0, meaning that libraries using that approach would have to drop support for php 7,
> or use a polyfill that doesn't free unused object keys, potentially leaking memory.


While I support the idea of a backport to expand people's options, I 
think a more likely approach for that situation will be to have a 
wrapper which uses either a dynamic property approach or a WeakMap 
approach depending on version / feature availability, as I outlined 
here: https://externals.io/message/115800#116268

Such a wrapper would make sense even without the deprecation, since 
WeakMap is generally a better tool for the job, e.g. it won't cause 
problems with classes implementing __set/__get. Of course, the 
class_exists as in that example will neatly use the better 
implementation if the backport extension is installed, so it's still a win.

Regards,

-- 
Rowan Tommins
[IMSoP]