Re: [PHP-DEV] [RFC][Draft] Add json_encode indent parameter

2021-06-15 Thread Jakub Zelenka
On Mon, Jun 7, 2021 at 11:53 AM Nikita Popov  wrote:

> On Thu, Jun 3, 2021 at 6:11 PM Timon de Groot 
> wrote:
>
> > Hi internals,
> >
> > I'd like to present my RFC for adding the indent parameter to the
> > json_encode function:
> >https://wiki.php.net/rfc/json_encode_indentation
> >
> > The `string|int $indent = 4` parameter adds the ability to specify the
> > indentation for
> > the JSON encoder. Amount of spaces can be specified by a number and a
> > string can be
> > specified to set a custom indentation like `\t` or whatever.
> >
> > As this is my first RFC (and contribution) for PHP, I'm all kind of new
> > to the process, standards, etc.
> > Please let me know if I could do something better.
> >
> > Looking forward to feedback/input on the RFC.
> >
>
> As has been brought up in
> https://github.com/php/php-src/pull/7093#issuecomment-855170601, the
> string
> version of the $indent parameter allows you to create invalid JSON,
> something that json_encode() does not currently allow. I tend to agree that
> it would make sense to validate that the indent only contains whitespace
> characters, and not .
>
>
I agree with this, it should validated to be also consistent with UTF-8
validation. For example if it's not valid utf8, it returns false (unless
ignoring or substitution is enabled). In any case it never returns invalid
json atm. I don't think it's a good idea to break that assumption.

Cheers

Jakub


Re: [PHP-DEV] [RFC][Draft] Add json_encode indent parameter

2021-06-07 Thread Nikita Popov
On Thu, Jun 3, 2021 at 6:11 PM Timon de Groot  wrote:

> Hi internals,
>
> I'd like to present my RFC for adding the indent parameter to the
> json_encode function:
>https://wiki.php.net/rfc/json_encode_indentation
>
> The `string|int $indent = 4` parameter adds the ability to specify the
> indentation for
> the JSON encoder. Amount of spaces can be specified by a number and a
> string can be
> specified to set a custom indentation like `\t` or whatever.
>
> As this is my first RFC (and contribution) for PHP, I'm all kind of new
> to the process, standards, etc.
> Please let me know if I could do something better.
>
> Looking forward to feedback/input on the RFC.
>

As has been brought up in
https://github.com/php/php-src/pull/7093#issuecomment-855170601, the string
version of the $indent parameter allows you to create invalid JSON,
something that json_encode() does not currently allow. I tend to agree that
it would make sense to validate that the indent only contains whitespace
characters, and not .

Regards,
Nikita


[PHP-DEV] [RFC][Draft] Add json_encode indent parameter

2021-06-03 Thread Timon de Groot

Hi internals,

I'd like to present my RFC for adding the indent parameter to the 
json_encode function:

  https://wiki.php.net/rfc/json_encode_indentation

The `string|int $indent = 4` parameter adds the ability to specify the 
indentation for
the JSON encoder. Amount of spaces can be specified by a number and a 
string can be

specified to set a custom indentation like `\t` or whatever.

As this is my first RFC (and contribution) for PHP, I'm all kind of new 
to the process, standards, etc.

Please let me know if I could do something better.

Looking forward to feedback/input on the RFC.

--

Kind regards,

Timon de Groot

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php