Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107913 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 5642 invoked from network); 16 Dec 2019 11:19:58 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 16 Dec 2019 11:19:58 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 6468F2C526B for ; Mon, 16 Dec 2019 01:19:35 -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: X-Spam-Virus: No Received: from mail01.nexxes.net (mail01.nexxes.net [IPv6:2a01:4f8:200:63e7:1::2]) (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 01:19:34 -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 5E333860649; Mon, 16 Dec 2019 10:19:32 +0100 (CET) To: Nikita Popov Cc: PHP internals References: <1d2d5c23-3864-a202-92a8-34228798510d@birkholz.biz> Message-ID: Date: Mon, 16 Dec 2019 10:19:32 +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 12.12.19 18:13, Nikita Popov wrote: > On Tue, Dec 10, 2019 at 12:03 PM Dennis Birkholz > 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... Greets Dennis