Re: Re: [RFC] Add WeakMap

From: Date: Mon, 16 Dec 2019 09:27:36 +0000
Subject: Re: Re: [RFC] Add WeakMap
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-107914@lists.php.net to get a copy of this message
On Mon, Dec 16, 2019 at 10:19 AM Dennis Birkholz <php@dennis.birkholz.biz> 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. Nikita

« previous php.internals (#107914) next »