Req #71057 [Com]: var_export uses long array syntax, is not PSR-2 compliant

From: Date: Wed, 10 Feb 2016 13:48:33 +0000
Subject: Req #71057 [Com]: var_export uses long array syntax, is not PSR-2 compliant
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199149@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71057&edit=1 ID: 71057 Comment by: shakaran at gmail dot com Reported by: marcus at synchromedia dot co dot uk Summary: var_export uses long array syntax, is not PSR-2 compliant Status: Not a bug Type: Feature/Change Request Package: Arrays related PHP Version: 5.6.16 Block user comment: N Private report: N New Comment: Please, could we reconsider opening this bug? Currently using var_export() for output arrays of arrays (for example doing translations) or big files with configs, it is very unreadable read a lot array() instead only []. And the syntax [] for arrays is specially usefull for non IT people because they understand pretty easily the keys and values for translations. Some people is even hardcoding this behaviour with regex and json as you can see: http://stackoverflow.com/questions/24316347/how-to-format-var-export-to-php5-4-array-syntax I am specially interested for this for example: https://github.com/barryvdh/laravel-translation-manager/issues/94#issuecomment-182273567 Probably this should be the default option, but could be implemented with a flag option parameter for new behaviour and make as default in upcoming versions since coulbe a BC if you change all the output in a lot php programs. At least the PHP user should could decide if he wants the new behaviour with a flag, and I think that it is pretty easy to implement that flag for output like that. Previous Comments: ------------------------------------------------------------------------ [2015-12-08 14:10:11] krakjoe@php.net The justification for short array syntax - that it is short - doesn't matter for generated code. What matters is that the output is predictable across PHP versions, for that reason it doesn't make sense to change the format of the output in order to comply with a PSR that doesn't apply to internals, and was never meant too. Definitely, not a bug ... ------------------------------------------------------------------------ [2015-12-08 11:20:00] marcus at synchromedia dot co dot uk Description: ------------ Calling var_export with an array parameter generates PHP code that uses old-style long array syntax instead of PHP 5.4-style short array syntax. There are also some spacing issues that mean that the generated code is not PSR-2 compliant (space after 'array' and 2-space indenting), and I don't see any good reason for that not to be the case. It appears that this behaviour occurs in all versions since PHP 5.4, including 7. Test script: --------------- var_export(['a' => 0]); Expected result: ---------------- [ 'a' => 0, ] Actual result: -------------- array ( 'a' => 0, ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71057&edit=1

« previous php.bugs (#199149) next »