Req #76811 [Opn]: Add option to var_export so arrays use brackets []
| From: | cmb@php.net | Date: | Mon, 23 Aug 2021 14:50:35 +0000 |
| Subject: | Req #76811 [Opn]: Add option to var_export so arrays use brackets [] | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-236022@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76811&edit=1
ID: 76811
Updated by: cmb@php.net
Reported by: mark at seventhcycle dot net
Summary: Add option to var_export so arrays use brackets []
Status: Open
Type: Feature/Change Request
-Package: Arrays related
+Package: Variables related
Operating System: Any
PHP Version: Next Minor Version
Block user comment: N
Private report: N
New Comment:
There is a respective RFC, but apparently that went nowhere.
[1] <https://wiki.php.net/rfc/var-export-array-syntax>
Previous Comments:
------------------------------------------------------------------------
[2018-08-29 22:38:15] cmb@php.net
Makes some sense, in my opinion. Instead of bool parameter, I'd
go for a bitset instead, since there may well be other useful
options. I suggest to discuss this on the internals@ mailing
list[1].
[1] <http://php.net/mailing-lists.php#internals>
------------------------------------------------------------------------
[2018-08-29 20:31:54] mark at seventhcycle dot net
Description:
------------
Right now, any arrays that are exported via var_export use the longer array() syntax.
What would be useful here is a third optional argument to var_export:
e.g: var_export($arr, FALSE, TRUE);
Where if the third argument is set to true, the output would use the shorter, PHP 5.4 syntax.
There are already functions out there (search for var_export54) that do this sort of thing, however,
it would be useful if this were in core PHP.
The third argument isn't necessary, however, I propose doing it this way to not break
compatibility for existing people who are using var_export.
Test script:
---------------
$arr = [
'key' => 'value',
'mushroom' => [
'badger' => 1
]
];
var_export($arr, FALSE, TRUE);
Expected result:
----------------
[
'key' => 'value',
'mushroom' => [
'badger' => 1
]
]
Actual result:
--------------
array (
'key' => 'value',
'mushroom' =>
array (
'badger' => 1,
),
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76811&edit=1