El sáb, 30 jul 2022 a las 8:30, Dusk (<d...@woofle.net>) escribió:

> On Jul 29, 2022, at 23:05, Aleksander Machniak <a...@alec.pl> wrote:
> > json_decode() has $depth argument, I think is_json() probably also
> should. And I'm not sure about JSON_INVALID_UTF8_IGNORE flag.
> >
> > My point is that if you use these with json_decode() you might also need
> to use these with is_json()
>
> How about if validation were a flag to json_decode() -- perhaps
> JSON_VALIDATE_ONLY -- which made it return a placeholder value like true
> instead of the decoded structure? (It can't return null on success; that's
> used for errors if JSON_THROW_ON_ERROR isn't set.)
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>
>

I thought about that too, and yes can also be a valid approach that would
not interfeer with my development.

What I personally dont like about that approach is that a developer is able
to specify flags that are related to exclusively with result generation,
and when they get mixed with JSON_VALIDATE_ONLY would not make sense. for
example:

json_decode($jsonStringHere, false, 512, JSON_BIGINT_AS_STRING |
JSON_INVALID_UTF8_SUBSTITUTE | JSON_OBJECT_AS_ARRAY | JSON_THROW_ON_ERROR |
JSON_VALIDATE_ONLY);

So the end result, is not clear by reading the line itself, I mean , the
mechanism (of having another constant in json_decode()) is not enough to
make the function self-expressive.

Reply via email to