> Le 30 août 2024 à 09:36, Philip Hofstetter <phofstet...@sensational.ch> a
> écrit :
>
> Hello,
>
> In the aftermath of an internal refactoring of an internal code-base to turn
> something eager into something more lazy using Generators, it occurred to me
> that while PHP refuses to serialize() a Generator, accidentally running
> json_encode() over a Generator produces the worst possible result:
>
> It silently encodes generators as {}.
>
> I would like to write an RFC to first deprecating and later disallowing to
> json_encode Generators.
>
Hi,
Note that the issue is not limited to Generators. For instance a Closure object
is also json-encodable but not serialisable.
IMO, every internal class (not just Generator) that is marked as
non-serialisable, should also be non-json-encodable.
—Claude