Hello Philip, Thank you for your RFC, which is a great effort to improve serialization in PHP. Generators are indeed super useful and working with them should not be confusing.
I regret that I missed your previous emails, but I would like to suggest that you consider the following concerns: 1. The original serialization and json_encode are not symmetric nor interchangeable by definition, because JSON doesn't preserve protected properties and class names. Hence, I don't see them to be "inconsistent" as they were not designed to be consistent. 2. The reason why some objects are not serializable is because they couldn't be fully functioning after deserialization. But this is not a barrier for JSON encoding, which serializing public properties only. Current JSON encoding has a simple, straight forward logic, not tied to serialization in any way. You have suggested to cast a non-serializable objects to array as a workaround. Yet, array is the most popular type to JSON in PHP. To me, an ideal move would be make json_encode to iterate any iterators from the input structure. Well, this is a different topic. Best regards, Vasilii On Tue, Sep 3, 2024, 7:26 AM Philip Hofstetter <phofstet...@sensational.ch> 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 > > >