Add support for shorthand array syntax to ArrayBracketSpacingSniff. #34

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@illusori
Contributor
illusori commented Jun 3, 2012

Adds support and unit tests for PHP 5.4 shorthand array syntax to ArrayBracketSpacingSniff.

This version just skips sniffing if it believes that the syntax is a shorthand array, rather than applying a different set of rules, but it would be easy to adapt the code to apply a new set of rules instead.

Fixes http://pear.php.net/bugs/bug.php?id=19416

@gsherwood
Member

Thanks a lot for patch. I decided to implement it slightly differently, using a blacklist (T_EQUAL) rather than a whitelist for square brackets. Essentially doing the same thing but ruling things out bit by bit.

Commit is here: b9f57bf

I'll close this now, but let me know if if anything is wrong.

@gsherwood gsherwood closed this Jun 4, 2012
@illusori
Contributor
illusori commented Jun 5, 2012

Ah, the reason I did it the way I did is because [] as an array is valid anywhere an expression is valid (from my understanding anyway, I don't have 5.4 installed anywhere handy to test at the moment), so that you can have situations like (but not limited to):

$value = ['key' => ['another', 'shorthand', 'array']];
$ret = myfunction($arg1, ['an array']);
$merged = $array + ['another' => 'array'];

As result it works out easier (IMO) to figure out if it's an array index use case, rather than if it's a short-hand array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment