atom feed99 messages in net.php.lists.internals[PHP-DEV] Short syntax for array lite...
FromSent OnAttachments
Stan Vassilev | FMMay 21, 2008 7:12 pm 
Felipe PenaMay 21, 2008 7:20 pm 
Stanislav MalyshevMay 21, 2008 8:53 pm 
Pierre JoyeMay 22, 2008 2:46 am 
Antony DovgalMay 22, 2008 2:56 am 
Pierre JoyeMay 22, 2008 3:33 am 
Johannes SchlüterMay 22, 2008 6:56 am 
Pierre JoyeMay 22, 2008 7:28 am 
Philip OlsonMay 22, 2008 8:55 am 
Stanislav MalyshevMay 22, 2008 9:17 am 
Andi GutmansMay 22, 2008 9:15 pm 
Brian MoonMay 22, 2008 9:29 pm 
LokrainMay 23, 2008 1:28 am 
Pierre JoyeMay 23, 2008 1:58 am 
Alexey ZakhlestinMay 23, 2008 2:06 am 
Jani TaskinenMay 23, 2008 4:45 am 
Eric ColemanMay 23, 2008 6:43 am 
Yi WangMay 23, 2008 8:17 am 
Sebastian DeutschMay 27, 2008 1:53 pm 
Sebastian DeutschMay 27, 2008 3:58 pm 
Stanislav MalyshevMay 27, 2008 4:10 pm 
Jani TaskinenMay 27, 2008 4:14 pm 
Stanislav MalyshevMay 27, 2008 4:18 pm 
Sebastian DeutschMay 27, 2008 4:21 pm 
Rasmus LerdorfMay 27, 2008 5:27 pm 
Andrei ZmievskiMay 27, 2008 5:48 pm 
73 later messages
Subject:[PHP-DEV] Short syntax for array literals [...]
From:Stan Vassilev | FM (sv_f@fmethod.com)
Date:May 21, 2008 7:12:26 pm
List:net.php.lists.internals

Hi,

I hear this often by other developers and I tend to agree with them, that arrays
are used often, and often nested, so that having a long syntax for array
literals tend to produce less legible code than in other scriping languages.

$a = array(array(1,2), array(3,4), 5, 6);

$b = array('a' => 1, 'b' =>2);

We use arrays in our configurations, in passing complex parameters to functions,
fetching information from databases, basically everything. So it adds up.

Some frameworks have somewhat funny attempts to remedy this by introducing
"shortcuts" like this: function a() { return func_get-args(); }. Of course
this doesn't work when you need to specify the key name, and the overhead isn't
worth it.

It looks as there may not be a specific reason not to allow the JS syntax as an
alternative syntax (while keeping the current one in parallel):

$a = [[1, 2], [3, 4], 5, 6];

$b = ['a' => 1, 'b' =>2];

There shouldn't be confusion to the parser as the brackets aren't preceded by an
identifier.

Was this discussed before on the list?

Regards, Stan Vassilev