atom feed88 messages in net.php.lists.internalsRE: Re[2]: [PHP-DEV] Proposal: Array ...
FromSent OnAttachments
Christian SchneiderNov 4, 2003 3:32 pm.patch
Rasmus LerdorfNov 4, 2003 5:06 pm 
Ken TossellNov 4, 2003 5:09 pm 
Andi GutmansNov 5, 2003 12:49 am 
Michael WalterNov 5, 2003 12:59 am 
Michael WalterNov 5, 2003 1:03 am 
Kouber SaparevNov 5, 2003 1:47 am 
Christian SchneiderNov 5, 2003 2:06 am 
s0niXNov 5, 2003 2:43 am 
Ford, Mike [LSS]Nov 5, 2003 3:20 am 
Mike RobinsonNov 5, 2003 3:26 am 
Dirkjan OchtmanNov 5, 2003 3:45 am 
Cesare D'AmicoNov 5, 2003 4:02 am 
Alexey TrunyovNov 5, 2003 4:34 am 
Antony DovgalNov 5, 2003 4:59 am 
Marco TabiniNov 5, 2003 5:04 am 
Ilia AlshanetskyNov 5, 2003 5:06 am 
Magnus MäättäNov 5, 2003 5:07 am 
Derick RethansNov 5, 2003 5:18 am 
Christian SchneiderNov 5, 2003 7:34 am 
Nicolas ToperNov 5, 2003 7:47 am 
Ilia AlshanetskyNov 5, 2003 7:56 am 
Antony DovgalNov 5, 2003 8:03 am 
Rasmus LerdorfNov 5, 2003 8:21 am 
Christian SchneiderNov 5, 2003 8:30 am 
Andrey HristovNov 5, 2003 8:40 am 
Ilia AlshanetskyNov 5, 2003 8:47 am 
Andi GutmansNov 5, 2003 8:47 am 
Jani TaskinenNov 5, 2003 8:49 am 
Ford, Mike [LSS]Nov 5, 2003 8:50 am 
Marco TabiniNov 5, 2003 8:52 am 
Christian SchneiderNov 5, 2003 8:54 am 
George SchlossnagleNov 5, 2003 8:58 am 
Jani TaskinenNov 5, 2003 8:59 am 
Christian SchneiderNov 5, 2003 9:00 am 
Ford, Mike [LSS]Nov 5, 2003 9:00 am 
52 later messages
Subject:RE: Re[2]: [PHP-DEV] Proposal: Array syntax
From:Mike Robinson (mi@fiddy8.com)
Date:Nov 5, 2003 3:26:55 am
List:net.php.lists.internals

s0niX wrote:

The problem i see when using array() (or list()) is that it nearly looks like it is a function, but it isn't. Using [] instead would clearly mark this difference. array() and list() are special language constructs, why shouldn't they look a bit special? This doesn't break backwards compatibility and it makes new code look better and more readable.

Indeed. It's a nice idea. Having that syntax as an alternative to list() would be cool too.

Whether it has enough steam to get around the magic rule I'll leave to others, because the rule is there for a reason. :)

Am Mittwoch, 5. November 2003 um 09:49 schrieben Sie:

AG> Hi Christian,

AG> Personally I don't like having two ways of doing things. It makes it harder AG> for people to read scripts. AG> However, I think the proposed syntax is significantly more elegant than AG> today's array() which makes me think twice about the idea and possibly AG> making an exception to the rule. I think it'll improve the look of PHP AG> scripts. Also I think people calling methods using call_user_method([$obj, AG> "method"]); will find it sexier than the array() syntax. AG> I guess I think it'd be interesting to see what other's think. Also, AG> another point to check is if list() can also be converted into [] because AG> having a hybrid wouldn't be too nice.

AG> Andi

AG> At 12:33 AM 11/5/2003 +0100, Christian Schneider wrote:

I propose to add an alternative (backward compatible) short array creation syntax: $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 :-)