The convention currently states: Do not put spaces in brackets when accessing array elements. However, this is awkward if the index is not a literal, especially if it is an expression that contains spaces. For example:
$a[0]
$a['foo']
$a[$i]
$a[$i + 1]
$a['x' . $name]
$a[$this->get( $something, foo)]
We seem to already deviate from the convention in such cases, I found more than 100 places in core that use spaces in array indexes. I propose to change the convention as follows: Do not put spaces in brackets when accessing array elements if the index is a literal or variable. Do put spaces after the opening bracket and before the closing bracket if the index is an expression that by convention should contain spaces anywhere. For example:
$a[0]
$a['foo']
$a[$i]
$a[ $i + 1 ]
$a[ 'x' . $name ]
$a[ $this->get( $something, foo) ]
I think that is much more readable and intuitive. What do you think?
I'd personally also be fine to always add spaces in array indexes, if that is preferable for consistency.