More magic. The difference between these two lines:
$a = array(1,2,3);
$a = [ 1,2,3 ];
is that with the first you can go and look up the array keyword and see
what it does, whereas on the second line you have no idea. You can't look
up a [
You are right that arrays are common and that this might be a case to
break the no-magic PHP rule, but I am personally not in favour of breaking
it for this case.
On Wed, 5 Nov 2003, Christian Schneider wrote:
I propose to add an alternative (backward compatible) short array
$a = [ 1, 2, 3 ]; and $a = [ 'a' => 42, 'b' => "foo" ];
It can also be used in function calls:
img(['src' => "logo.gif", 'alt' => "Logo"]);
Reason behind this change: Arrays are used a lot and should therefore
have as little syntactic overhead as possible. And I think the short
syntax is also easier to read and write.
A patch for the parser is trivial and is attached for Zend2.
Note: I checked the newsgroup archive but couldn't find a discussion
about this. After not hearing back about my proposed enhancement to
debug_backtrace() and the dangling comma for function call parameters
being rejected I wonder if I'm using the right mailing list for this :-)