Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104192 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 93043 invoked from network); 5 Feb 2019 19:25:04 -0000 Received: from unknown (HELO mail01.nexxes.net) (144.76.185.252) by pb1.pair.com with SMTP; 5 Feb 2019 19:25:04 -0000 Received: from [192.168.0.193] (unknown [93.159.255.203]) (Authenticated sender: db220660-p0g-1) by mail01.nexxes.net (Postfix) with ESMTPSA id 242EC86056D; Tue, 5 Feb 2019 17:06:14 +0100 (CET) To: Nikita Popov Cc: Joe Watkins , PHP internals References: <2fed98af-3831-1a1c-def8-04793fcc0c6f@birkholz.biz> Message-ID: <2a566239-d205-72f8-fd78-630b7ff01581@birkholz.biz> Date: Tue, 5 Feb 2019 17:06:13 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] RFC Weakrefs From: php@dennis.birkholz.biz (Dennis Birkholz) 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