Re: Re: [RFC] Add WeakMap
| From: | Dennis Birkholz | Date: | Mon, 16 Dec 2019 11:10:00 +0000 |
| Subject: | Re: Re: [RFC] Add WeakMap | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-107916@lists.php.net to get a copy of this message | ||
On 16.12.19 10:27, Nikita Popov wrote:
On Mon, Dec 16, 2019 at 10:19 AM Dennis Birkholz <php@dennis.birkholz.biz> wrote: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.On 12.12.19 18:13, Nikita Popov wrote: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.On Tue, Dec 10, 2019 at 12:03 PM Dennis Birkholz <php@dennis.birkholz.biz>wrote: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...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}