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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php