Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107916 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 31520 invoked from network); 16 Dec 2019 13:10:25 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 16 Dec 2019 13:10:25 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id ABF1D2C84C2 for ; Mon, 16 Dec 2019 03:10:03 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS24940 144.76.0.0/16 X-Spam-Virus: No Received: from mail01.nexxes.net (mail01.nexxes.net [144.76.185.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Mon, 16 Dec 2019 03:10:02 -0800 (PST) Received: from [192.168.0.193] (unknown [93.159.255.203]) (Authenticated sender: db220660-p0g-1) by mail01.nexxes.net (Postfix) with ESMTPSA id 41A1F860649; Mon, 16 Dec 2019 12:10:01 +0100 (CET) To: Nikita Popov Cc: PHP internals References: <1d2d5c23-3864-a202-92a8-34228798510d@birkholz.biz> Message-ID: <8745e88f-93bc-16b1-e967-3becd00516e4@birkholz.biz> Date: Mon, 16 Dec 2019 12:10:00 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.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 X-Envelope-From: Subject: Re: [PHP-DEV] Re: [RFC] Add WeakMap From: php@dennis.birkholz.biz (Dennis Birkholz) On 16.12.19 10:27, Nikita Popov wrote: > On Mon, Dec 16, 2019 at 10:19 AM Dennis Birkholz > wrote: > >> On 12.12.19 18:13, Nikita Popov wrote: >>> On Tue, Dec 10, 2019 at 12:03 PM Dennis Birkholz < >> php@dennis.birkholz.biz> >>> wrote: >>>> But my just want to repeat my main concern: buildin >>>> data structures that are not serializable are a real problem for users >>>> that use serialization extensively. Maybe the solution to that problem >>>> is a method to check whether a provided object graph can be serialized >>>> (which may not be possible due to throwing an exception in __sleep() or >>>> something like that), some way to ignore unserializable elements or some >>>> way to register callback methods to handle unserializable elements. >>>> >>> >>> I'm must be missing something obvious here: Isn't this a reliable way to >>> detect whether an object graph is serializable? >>> >>> try { >>> $serialized = serialize($value); >>> } catch (\Throwable $e) { >>> // not serializable >>> } >> >> Checking whether the serialization process worked is different from >> checking beforehand whether an object graph is serializable as it makes >> it a lot easier to display a meaningful error message. Something like >> the Serializable interface in Java. But that seems to not be the PHP way >> so far, I will have to think about an RFC for a second parameter for >> serialize() that accepts a callback that can "serialize" >> objects/variables that fail to serialize themselves... >> > > Could you please explain in more detail what the practical distinction > between checking beforehand and catching an exception is? It seems like the > exception should be sufficient to display a meaningful error message -- > heck, it already contains an error message you can use. The practical distinction would be the error is raised in the moment I build the object graph and assign a value that is not serializable and not in the moment I try to serialize. If my object graph is very complex finding the culprit is a lot easier that way. But typical PHP way is not to force each and every object in the graph to implement some interface that makes each object serialization safe (like in the Java Serializable case). From my side there is no need to continue this discussion. There seems to be no easy and sensible way to make WeakMap serializable so I rest my case. Nevertheless I appreciate that you took your time to discuss this Nikita.