Re: Re: [RFC] var_representation() : readable alternative to var_export()
| From: | Nikita Popov | Date: | Thu, 04 Feb 2021 19:53:23 +0000 |
| Subject: | Re: Re: [RFC] var_representation() : readable alternative to var_export() | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-113084@lists.php.net to get a copy of this message | ||
On Thu, Feb 4, 2021 at 3:36 PM tyson andre <tysonandre775@hotmail.com>
wrote:
> Hi internals,
>
> > I've created
> > https://wiki.php.net/rfc/readable_var_representation based
> on
> > my original proposal in
> > https://externals.io/message/112924
> >
> > This RFC proposes adding a new function `var_representation(mixed
> $value, int $flags=0): string`
> > with the following differences from var_export:
> >
> > 1. var_representation() unconditionally returns a string
> > 2. Use
null instead of
> > NULL - lowercase is recommended by more coding
> > guidelines (https://www.php-fig.org/psr/psr-2/).
> > 3. Change the way indentation is done for arrays/objects.
> > See ext/standard/tests/general_functions/short_var_export1.phpt
> > (e.g. always add 2 spaces, never 3 in objects, and put the array
> start on the
> > same line as the key)
> > 4. Render lists as "['item1']" rather
> > than `"array(\n 0 =>
> 'item1',\n)"`
> >
> > Always render empty lists on a single line, render multiline by
> default when there are 1 or more elements
> > 5. Prepend \ to class names so that generated code
> > snippets can be
> used in
> > namespaces without any issues.
> > 6. Support VAR_REPRESENTATION_SINGLE_LINE in
> > $flags.
> > This will use a single-line representation for arrays/objects, though
> > strings with embedded newlines will still cause newlines in the
> output.
> > 7. If a string contains control characters("\x00"-"\x1f" and
> "\x7f"(backspace)),
> > then represent the entire string as a double quoted string
> > escaping \r, \n,
> > \t, \$,
> > \\, and \", in addition to
> escaping remaining control characters
> > with hexadecimal encoding (\x00, \x7f, etc)
> >
> > This is different from my original proposal in two ways:
> > 1. The function signature and name changed from my previous proposal.
> > It now always returns a string.
> > 2. Backspace control characters (\x7f) are now also escaped.
>
> A reminder that voting on the var_representation RFC starts in a day.
> This RFC proposes adding a new function `var_representation(mixed $value,
> int $flags=0): string with multiple improvements on
> var_export()`.
>
> Any other feedback?
>
> Thanks,
> - Tyson
>
Given the recent discussion in the interactive shell thread, I think you
should consider whether the new function could also be expanded to serve
that use case. I think that if we're going to add one more dumping function
to the 4 we already have, it better cover all the use-cases we have. The
"limited size dump" doesn't really fit in with "dump is executable PHP
code", but if I understand correctly, executable PHP code is not the whole
goal of the proposal.
Regards,
Nikita