2
According to the PHP Handbook, about the function var_export
var_export()
gets structured information about a given variable. It is similar tovar_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 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 that same array (even in PHP 5.4), it returns this to me:
array ( 0 => 1, 1 => 2, 2 => 3, )
I would like the var_export
returns the array this way:
[ 0 => 1, 1 => 2, 2 => 3, ]
Is there any way to resolve this situation?
PHP has already fixed this in newer versions?
Why don’t you use the
var_dump()
even?– Jorge B.