rfc:var-export-array-syntax
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:var-export-array-syntax [2020/03/29 17:56] – googleguy | rfc:var-export-array-syntax [2020/04/10 09:24] (current) – typos, examples guilliamxavier | ||
---|---|---|---|
Line 12: | Line 12: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | Instead of <code php> | + | This change proposes adding a third optional argument for '' |
+ | |||
+ | - VAR_EXPORT_SHORT_ARRAY | ||
+ | - VAR_EXPORT_NO_INDEX | ||
+ | - VAR_EXPORT_COMPACT | ||
+ | |||
+ | '' | ||
+ | |||
+ | Each option can be used alone, and can also be combined with other(s). | ||
+ | |||
+ | |||
+ | For example, < | ||
+ | |||
+ | <code php> | ||
+ | array ( | ||
+ | 0 => 1, | ||
+ | 1 => 2, | ||
+ | 2 => 3, | ||
+ | ) | ||
+ | </ | ||
+ | |||
+ | and the new < | ||
+ | |||
+ | <code php> | ||
+ | [ | ||
+ | 0 => 1, | ||
+ | 1 => 2, | ||
+ | 2 => 3, | ||
+ | ] | ||
+ | </ | ||
+ | |||
+ | This would affect '' | ||
+ | |||
+ | So the following changes | ||
+ | |||
+ | <code php> | ||
+ | $obj = new stdClass; | ||
+ | $obj-> | ||
+ | $obj-> | ||
+ | |||
+ | var_export($obj); | ||
+ | /* | ||
+ | (object) array( | ||
+ | ' | ||
+ | ' | ||
+ | ) | ||
+ | */ | ||
+ | |||
+ | var_export($obj, | ||
+ | /* | ||
+ | (object) [ | ||
+ | ' | ||
+ | ' | ||
+ | ] | ||
+ | */ | ||
+ | </ | ||
+ | |||
+ | Same for other classes: | ||
+ | |||
+ | <code php> | ||
+ | class Foo { | ||
+ | public $bar = " | ||
+ | } | ||
+ | |||
+ | var_export(new Foo); | ||
+ | /* | ||
+ | Foo:: | ||
+ | ' | ||
+ | )) | ||
+ | */ | ||
+ | |||
+ | var_export(new Foo, false, VAR_EXPORT_SHORT_ARRAY); | ||
+ | /* | ||
+ | Foo:: | ||
+ | ' | ||
+ | ]) | ||
+ | */ | ||
+ | </ | ||
+ | |||
+ | Using the other bitwise flags you could also do things like... | ||
+ | |||
+ | <code php> | ||
+ | var_export([1, 2, 3], false, VAR_EXPORT_NO_INDEX); | ||
+ | /* | ||
+ | array ( | ||
+ | 1, | ||
+ | 2, | ||
+ | 3, | ||
+ | ) | ||
+ | */ | ||
+ | |||
+ | var_export([1, | ||
+ | /* | ||
+ | array (0 => 1, 1 => 2, 2 => 3) | ||
+ | */ | ||
+ | </ | ||
+ | |||
+ | and combine them... | ||
+ | |||
+ | <code php> | ||
+ | var_export([1, | ||
+ | /* | ||
+ | [ | ||
+ | 1, | ||
+ | 2, | ||
+ | 3, | ||
+ | ] | ||
+ | */ | ||
+ | |||
+ | var_export([1, | ||
+ | /* | ||
+ | [0 => 1, 1 => 2, 2 => 3] | ||
+ | */ | ||
+ | |||
+ | var_export([1, | ||
+ | /* | ||
+ | array (1, 2, 3) | ||
+ | */ | ||
+ | |||
+ | var_export([1, | ||
+ | /* | ||
+ | [1, 2, 3] | ||
+ | */ | ||
+ | </ | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 39: | Line 162: | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | The change only requires changing two lines in '' | + | The change only requires changing two lines in '' |
+ | |||
+ | See https:// | ||
===== Implementation ===== | ===== Implementation ===== | ||
Line 45: | Line 170: | ||
===== References ===== | ===== References ===== | ||
https:// | https:// | ||
+ | |||
https:// | https:// | ||
+ | |||
+ | https:// | ||
===== Rejected Features ===== | ===== Rejected Features ===== | ||
rfc/var-export-array-syntax.1585504594.txt.gz · Last modified: 2020/03/29 17:56 by googleguy