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] -- PECL development discussion Mailing List (https://pecl.php.net/) To unsubscribe, visit: https://www.php.net/unsub.php