How to make var_export export array in short syntax

2

According to the PHP Manual, on the var_export function

  

var_export() gets structured information about a given variable. She   is similar to var_dump() with one exception: the returned representation is a   valid PHP code.

That is, it should return a valid PHP code for a given value passed by parameter.

The problem is that in PHP 5.4, the settings for a array have changed. You no longer need to use the keyword array , but only use the square brackets.

Example:

// Versões anteriores ao PHP 5.4
$a = array(1, 2, 3);
// Versões iguais ou posteriores ao PHP 5.4
$a = [1, 2, 3]

When I do the var_export in this same array (even in PHP 5.4), it returns me this:

array ( 0 => 1, 1 => 2, 2 => 3, )

I would like var_export to return the array like this:

[ 0 => 1, 1 => 2, 2 => 3, ]

Is there any way to resolve this?

Has PHP already fixed this in newer versions?

    
asked by anonymous 15.07.2015 / 17:24

1 answer

3

var_export continues exporting the variables in array() format to latest versions .

Although PHP 5.4 introduces the simplified syntax of arrays with [ ] brackets, the use of arrays in the array() format continues to work without problems.

Changing the output of var_export to short syntax would only bring more problems to those who use old versions and is a superfluous change, since the common syntax still works array() .

Maybe in the future when array() no longer exists this will be changed.

    
15.07.2015 / 17:33