On Tue, Oct 24, 2017 at 7:32 AM, Stanislav Malyshev <[email protected]>
wrote:
> Hi!
>
> > It's not terribly unreasonable IMO, but before I just writeup the RFC
> > as described (jsonRawSerialize taking preceedence over jsonSerialize),
> > I thought I'd ask for opinions on the specifics.
> >
> > In psuedo-code:
> >
> > if (is_object($obj)) {
> > if ($obj implements JsonRawSerializable) {
> > // use $obj->jsonRawSerialize() as is.
> > } elseif ($obj implements JsonSerializble) {
> > // use json_encode($obj->jsonSerialize())
> > } else {
> > // Serialize the object's public properties as a key/value map
> > }
> > }
>
> I'm not sure I feel very comfortable with having specialized serialize
> interfaces for every format, yet more with having more than one of them.
>
> There's also validation problem - if we don't ensure this is valid JSON,
> then whole serialization setup is broken, and who knows which
> consequences this will bring.
>
>
I fully agree with this. In addition to validation we wouldn't be able to
assure that options work as well. For example consider options
like JSON_HEX_*, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES,
JSON_FORCE_OBJECT, JSON_PRESERVE_ZERO_FRACTION, JSON_UNESCAPED_UNICODE and
some other encode options.
I think this is not a good idea and can cause many problems. So -1 from me.
Cheers
Jakub