rfc:readable_var_representation
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:readable_var_representation [2021/01/23 20:59] – tandre | rfc:readable_var_representation [2021/02/19 15:19] (current) – vote declined tandre | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: var_representation() : readable alternative to var_export() ====== | ====== PHP RFC: var_representation() : readable alternative to var_export() ====== | ||
- | * Version: 0.2 | + | * Version: 0.3 |
* Date: 2021-01-22 | * Date: 2021-01-22 | ||
* Author: Tyson Andre, tandre@php.net | * Author: Tyson Andre, tandre@php.net | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
* Implementation: | * Implementation: | ||
Line 25: | Line 25: | ||
- Always render empty lists on a single line instead of two lines. | - Always render empty lists on a single line instead of two lines. | ||
- Prepend '' | - Prepend '' | ||
- | - Support the bit flag '' | + | - Support the bit flag '' |
<code php> | <code php> | ||
Line 49: | Line 49: | ||
php > echo var_representation([]); | php > echo var_representation([]); | ||
[] | [] | ||
+ | // lines are indented by a multiple of 2, similar to var_export but not exactly the same | ||
+ | php > echo var_representation([(object) [' | ||
+ | [ | ||
+ | (object) [ | ||
+ | ' | ||
+ | ' | ||
+ | 1.0, | ||
+ | ], | ||
+ | ' | ||
+ | 2, | ||
+ | ]), | ||
+ | ], | ||
+ | ' | ||
+ | ], | ||
+ | ] | ||
</ | </ | ||
Line 62: | Line 77: | ||
' | ' | ||
] | ] | ||
+ | |||
+ | |||
</ | </ | ||
Line 330: | Line 347: | ||
Adding more flags here would increase the scope of the rfc and complexity of implementing the change and for reviewing/ | Adding more flags here would increase the scope of the rfc and complexity of implementing the change and for reviewing/ | ||
+ | |||
+ | === Supporting an indent option === | ||
+ | |||
+ | This was left out since I felt it would increase the scope of the RFC too much. | ||
+ | |||
+ | If an '' | ||
+ | |||
+ | The fact that embedded newlines are now no longer emitted as parts of strings makes it easier to efficiently convert the indentation to spaces or tabs using '' | ||
+ | |||
+ | <code php> | ||
+ | php > echo var_representation([[[' | ||
+ | [ | ||
+ | [ | ||
+ | [ | ||
+ | ' | ||
+ | ], | ||
+ | ], | ||
+ | ] | ||
+ | php > echo preg_replace('/ | ||
+ | [ | ||
+ | [ | ||
+ | [ | ||
+ | ' | ||
+ | ], | ||
+ | ], | ||
+ | ] | ||
+ | </ | ||
+ | ```` | ||
==== Adding magic methods such as __toRepresentation() to PHP ==== | ==== Adding magic methods such as __toRepresentation() to PHP ==== | ||
Line 347: | Line 392: | ||
It may be useful to override this string representation through additional flags, callbacks, or other mechanisms. | It may be useful to override this string representation through additional flags, callbacks, or other mechanisms. | ||
However, I don't know if there' | However, I don't know if there' | ||
+ | |||
+ | ==== Emitting code comments in result about references/ | ||
+ | |||
+ | Adding a comment such as ''/ | ||
+ | |||
+ | (Or ''/ | ||
===== Discussion ===== | ===== Discussion ===== | ||
Line 419: | Line 470: | ||
The last time '' | The last time '' | ||
- | ===== Proposed Voting Choices | + | ===== Vote ===== |
- | Yes/No, requiring 2/3 majority. | + | This is a Yes/ |
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== References ===== | ===== References ===== | ||
Line 577: | Line 633: | ||
- This may be much slower and end users may not expect that - a lot of small stream writes with dynamic C function calls would be something I'd expect to take much longer than converting to a string then writing to the stream. | - This may be much slower and end users may not expect that - a lot of small stream writes with dynamic C function calls would be something I'd expect to take much longer than converting to a string then writing to the stream. | ||
- Adding even more ways to dump to a stream/ | - Adding even more ways to dump to a stream/ | ||
+ | |||
+ | ==== Changing var_dump ==== | ||
+ | |||
+ | var_dump is a function which I consider to have goals that are incompatible ways. | ||
+ | If an exact representation of reference cycles, identical objects, and circular object data is needed, the code snippet '' | ||
+ | |||
+ | In particular, var_dump() dumps object ids, indicates objects that are identical to each other, shows recursion, and shows the presence of references. It also redundantly annotates values with their types, and generates output for types that cannot be evaluated (e.g. '' | ||
+ | |||
+ | Adding a comment such as ''/ | ||
+ | |||
+ | https:// | ||
===== Changelog ===== | ===== Changelog ===== | ||
* 0.2: Add the section "When would a user use var_representation?" | * 0.2: Add the section "When would a user use var_representation?" | ||
+ | * 0.3: Add more examples, add discussion section on indent |
rfc/readable_var_representation.1611435599.txt.gz · Last modified: 2021/01/23 20:59 by tandre