On Thu, Dec 5, 2019 at 6:09 PM Dennis Birkholz <p...@dennis.birkholz.biz>
wrote:

> Hi Nikita,
>
> Am 04.12.19 um 19:50 schrieb Nikita Popov:
> >> This RFC proposes to add a native WeakMap type for PHP 8:
> >> https://wiki.php.net/rfc/weak_maps
> >
> > Any comments on this proposal? Otherwise this could head to voting...
>
> thanks for this proposal, will be really helpful!
>
> The only caveat for me is that WeakMap is not serializable. Wouldn't it
> be possible to allow serialization by just serializing it as an array
> with all objects that are still valid? This would avoid serialization
> errors and make using it with serialization very easy. It would not
> unserialize as a WeakMap but that is not that a great problem for me.
>

This is not possible. Classes always have to serialize to themselves ;)


> Or maybe it could extend SplObjectStorage (or implement the same [new]
> interface) and could be serialized as an SplObjectStorage object instead
> of an array.
>

Could you provide some context on why you think serialization support for
WeakMap is important? As weak maps are essentially caching structures,
serializing them doesn't seem particularly useful in the first place, but
when combined with the quite unintuitive behavior the serialization would
have, I feel that it is better to leave this to the user (same as
WeakReference).

Specifically what I mean by uninituitive is this: When you do a $s =
serialize($weakMap), you'll get back a large payload string, but when you
then try to do an unserialize($s) you'll get back an empty WeakMap (or
worse: a weak map that will only become empty on the next GC), because all
of those objects will get removed as soon as unserialization is finalized.
That "works", but doesn't seem terribly useful and is likely doing to be a
wtf moment.

Nikita

Reply via email to