Proposal for a new Array Syntax in PHP

PHP LogoA new array syntax has been proposed (for quite some time) for defining arrays in PHP. Currently, we use array() construct to create an array. Some examples could be:

$myArray = array(1, 2, 3, 4, 5);
$yourArray = array(1 => “one”, 2 => “two”, “three”);
$herArray = array(1, 2, 3, array(4 => “four”, “five”));

The proposal is to use square brackets ( [ ] ) to define an array. If passed, we would be able rewrite the above examples as:


$myArray = [1, 2, 3, 4, 5];
$yourArray = [1 => “one”, 2 => “two”, “three”);
$herArray = [1, 2, 3, [4 => “four”, “five”]];

There’s a good deal of discussion going on in the internal mailing list with almost equal number of people voting “for” and “against” it. Rasmus, isn’t not very supportive, yet has voted for the new proposal.

To be pretty honest, I am still not very sure if it’s going to be worth the trade-offs.
Anyhoo! Let’s wait and watch. 🙂