Re: RFC: Deprecate json_encode() on classes marked as non-serializable
| From: | Rob Landers | Date: | Wed, 04 Sep 2024 19:41:17 +0000 |
| Subject: | Re: RFC: Deprecate json_encode() on classes marked as non-serializable | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-125421@lists.php.net to get a copy of this message | ||
On Tue, Sep 3, 2024, at 13:24, Philip Hofstetter wrote:
> Hello,
>
> As per my previous email to the list, I have now created the official RFC to deprecate calling
> json_serialize() on instances of classes marked with ZEND_ACC_NOT_SERIALIZABLE.
>
> https://wiki.php.net/rfc/deprecate-json_encode-nonserializable
>
> I have also created a PR with the implementation here:
>
> https://github.com/php/php-src/pull/15724
>
> I have considered other options, both constraining the implementation to just Generator and/or
> to add special cases for Generator (and maybe Iterator), but they either continue to keep the
> asymmetry between serialize() and json_encode() and/or are making things even more inconsistent.
>
> Please tell me what you think, especially, if you agree that blanked-deprecating all of
> ZEND_ACC_NOT_SERIALIZABLE classes is acceptable BC-wise (after a bit of deliberation over the
> weekend, I think it is and most json-serializations of such marked classes are probably
> unintentional).
>
> Thanks in advance for all comments
>
> Philip
>
>
Hello Phillip.
I think it would be good to list these non-serializable objects in the RFC. It doesn't have to
be exhaustive, but the list includes throwables, weak-maps, weak-references, closures, fibers, etc.
Some people may be relying on this behavior (and I'd be curious to know that use case myself).
I just grepped for @not-serializable in php-src stubs, which appears to be the only use of
ZEND_ACC_NOT_SERIALIZABLE.
— Rob