Re: json_encode() and Generators / RFC Karma

From: Date: Fri, 30 Aug 2024 14:47:43 +0000
Subject: Re: json_encode() and Generators / RFC Karma
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-125363@lists.php.net to get a copy of this message
> Le 30 août 2024 à 09:36, Philip Hofstetter <phofstetter@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

« previous php.internals (#125363) next »