Pecl proposal: weakreference_bc: Polyfilling WeakReference/WeakMap classes in php 7.1-7.4
| From: | tyson andre | Date: | Sat, 04 Dec 2021 23:13:00 +0000 |
| Subject: | Pecl proposal: weakreference_bc: Polyfilling WeakReference/WeakMap classes in php 7.1-7.4 | ||
| Groups: | php.pecl.dev | ||
| Request: | Send a blank email to pecl-dev+get-17454@lists.php.net to get a copy of this message | ||
Hi,
I'd started work on https://github.com/TysonAndre/pecl-weakreference_bc
- it's nearly finished, and I'd like to add it as a PECL.
- This is a fork of the https://pecl.php.net/package/weakref pecl (using the
WeakReference::create API instead of
new WeakRef), which was abandoned in 2016 because
the project maintainers believed php 7.3 support was impractical. (standard object handler arrays
became constant, but I worked around that. I didn't see discussion of specifics of
compatibility issues on the issue tracker..)
I believe the issues were fixed in this fork - many tests of php-src's WeakReference/WeakMap
are now passing (or behaving slightly differently without crashing) in the PECL, and I can use
simple scripts with php's development server (php -S) to test MINIT + repeated
RINIT+RSHUTDOWN.
- This omits WeakReference in 7.4 because it's already declared.
- This aims to match the API of WeakReference exactly (removes acquire(), release(), valid(),
dynamic property support, etc) - many end users would not want to support multiple different APIs.
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.
> Instead, a WeakMap should be used to store the information in a non-intrusive way:
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.
So having a PECL providing a native polyfill would be useful when upgrading older installations to
php 8.2+.
Thoughts?
Thanks,
Tyson