A +1 from me (in case my vote counts).

The main reason behind it is readability:

$x = array(1 => array(1, 2, 3), array(array(1), 2));

vs.

$x = [1 => [1, 2, 3], [[1], 2]];

The latter form looks much better to me - it is faster to read and to understand it (and to type it, of course, although it shouldn't be a factor), especially for such multi-dimensional definitions.

The benefit of using the new syntax is even bigger when dealing with function calls + conditionals:

if (in_array($z, array(1, 2, 3))) {
  $s = str_replace(array('a', 'b', 'c'), array('d', 'e', 'f'), 'abc');
}

vs.

if (in_array($z, [1, 2, 3])) {
  $s = str_replace(['a', 'b', 'c'], ['d', 'e', 'f'], 'abc');
}

With the "square brackets" syntax a pair of redundant parantheses is removed, thus making it easier to distinguish between data definition and function call (conditional, expression...) closures and helping identify arrays among such compound structures. ;-)

Regards,
--
Kouber Saparev
http://kouber.saparev.com

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to