Re: Proposal: short_var_export($value, bool $return=false, int $flags=0)

From: Date: Tue, 19 Jan 2021 14:25:28 +0000
Subject: Re: Proposal: short_var_export($value, bool $return=false, int $flags=0)
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-112926@lists.php.net to get a copy of this message
> Hi Tyson, > > The formatting of var_export is certainly a recurring complaint, and > previous discussions were not particularly open to changing current > var_export behavior, so adding a new function seems to be the way to > address the issue (the alternative would be to add a flag to var_export). > > I like the idea of the "one line" flag. Actually, this is the main part I'm > interested in :) With the one line flag, this produces the ideal formatting > for PHPT tests that want to print something like "$v1 + $v2 = $v3". None of > our current dumping functions are suitable for this purpose (json_encode > comes closest, but has edge cases like lack of NAN support.) > > Some note: > * You should drop the $return parameter and make it always return. As this > is primarily an export and not a dumping function, printing to stdout > doesn't make sense to me. > * For strings, have you considered printing them as double-quoted and > escaping more characters? This would avoid newlines in oneline mode. And > would allow you to escape more control characters. I also find the current > '' . "\0" . '' format for encoding null bytes quite awkward. > * I don't like the short_var_export() name. Is "short" really the primary > characteristic of this function? Both var_export_pretty and > var_export_canonical seem better to me, though I can't say they're great > either. I will refrain from proposing real_var_export() ... oops :P > > Regards, > Nikita > Sorry for the plug, but you may be interested in getting inspiration from brick/varexporter: https://github.com/brick/varexporter In particular: - uses short array syntax always - doesn't output array keys for lists - can output lists of scalars on one line, under a flag: INLINE_NUMERIC_SCALAR_ARRAY - Benjamin

« previous php.internals (#112926) next »