Hi Nikita,

On 05.02.19 16:50, Nikita Popov wrote:
Serialization for weak refs is a bit tricky, and I feel like supporting it could easily become a foot-gun. The fundamental problem is that for serialization to produce a meaningful value, the object referenced by a WeakReference must also be part of the serialized object graph as a strong reference somewhere. Otherwise, the WeakReference will immediately turn into a dud when unserialization ends, because the object it references is no longer live.

I think from a technical perspective, supporting serialization should be possible and not overly hard, it's more a question of whether we want to. As another data point, Java does not support serialization for WeakReference.

my fundamental problem here is that you can not reliably find out if something can be serialized or not. Each class that is not serializable by documentation/implementation but does not provide some programatical way of checking this adds another burden to create a special case for that class.

So I would really prefer the WeakReference class would just be serializable with all the consequences you outlined. Maybe for PHP 8 we will decide to require all classes to be serializable except classes that implement the Unserializable interface or something... Or the magic __isSerializable() method that can decide this at runtime for the actual state of an object without failing hard when trying it.

Greets
Dennis

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to