atom feed88 messages in net.php.lists.internalsRe: [PHP-DEV] Proposal: Array syntax
FromSent OnAttachments
30 earlier messages
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 
Marco TabiniNov 5, 2003 9:01 am 
Marco TabiniNov 5, 2003 9:05 am 
Ford, Mike [LSS]Nov 5, 2003 9:07 am 
Ford, Mike [LSS]Nov 5, 2003 9:09 am 
Marco TabiniNov 5, 2003 9:18 am 
Romans MalinovskisNov 5, 2003 9:19 am 
Andi GutmansNov 5, 2003 9:20 am 
StephNov 5, 2003 9:25 am 
Andrey HristovNov 5, 2003 9:25 am 
Ilia AlshanetskyNov 5, 2003 9:25 am 
Marco TabiniNov 5, 2003 9:30 am 
Derick RethansNov 5, 2003 9:33 am 
George SchlossnagleNov 5, 2003 9:36 am 
Rasmus LerdorfNov 5, 2003 9:45 am 
Edin KadribasicNov 5, 2003 9:45 am 
Romans MalinovskisNov 5, 2003 9:48 am 
Moriyoshi KoizumiNov 5, 2003 9:50 am 
Jani TaskinenNov 5, 2003 9:54 am 
Jaap van GanswijkNov 5, 2003 10:06 am 
Michael WalterNov 5, 2003 10:12 am 
Cesare D'AmicoNov 5, 2003 10:22 am 
Marco TabiniNov 5, 2003 10:28 am 
Michael WalterNov 5, 2003 10:30 am 
Michael WalterNov 5, 2003 10:35 am 
George SchlossnagleNov 5, 2003 10:36 am 
Andrei ZmievskiNov 5, 2003 10:39 am 
George SchlossnagleNov 5, 2003 10:56 am 
David EndersonNov 5, 2003 11:02 am 
Marco TabiniNov 5, 2003 11:10 am 
Shane CaraveoNov 5, 2003 11:12 am 
Michael WalterNov 5, 2003 12:26 pm 
Greg MacLellanNov 5, 2003 12:40 pm 
Robert CummingsNov 5, 2003 1:08 pm 
David EndersonNov 5, 2003 1:19 pm 
Sara GolemonNov 5, 2003 2:40 pm 
George SchlossnagleNov 5, 2003 3:00 pm 
Wez FurlongNov 5, 2003 4:06 pm 
Christian SchneiderNov 5, 2003 5:07 pm 
Ard BiesheuvelNov 5, 2003 5:27 pm 
Christian SchneiderNov 5, 2003 5:50 pm 
Andi GutmansNov 6, 2003 12:03 am 
Stig S. BakkenNov 6, 2003 12:58 am 
Kouber SaparevNov 6, 2003 1:24 am 
Mike RobinsonNov 6, 2003 3:31 am 
8 later messages
Subject:Re: [PHP-DEV] Proposal: Array syntax
From:Jaap van Ganswijk (gans@xs4all.nl)
Date:Nov 5, 2003 10:06:51 am
List:net.php.lists.internals

At 2003-11-05 09:59 +0100, Michael Walter wrote:

Very cool.

How about supporting .. syntax, btw. as in [1..3] or ["a".."z"]? Might no be the
worth, just thinking out loud ;)

I'm also in favor of a shorter notation for array() and list().

In fact this also helps to ease the problem I have with 'foreach ($A as $I=>$d)', because it would then be possible to write: while ([$i,$d]=each($A)). It's still not as short as I'd like it to be: 'while ($i=>$d in $A)', but it's already a lot better.

I'd also like to see ranges supported and propose to add notations for inclusive and non-inclusive ranges as: 1..3 inclusive at both ends so equal to 1,2,3 1.<3 non inclusive at the end so equal to 1,2 1>.3 non inclusive at the beginning so equal to 2,3 1><3 non inclusive at both ends so equal to 2

Of course generally only the first two variations are being used.

(Please note that this syntax conflicts slightly with the syntax of floating point numbers and compares. Perhaps it's solvable by scanning '..', '.<', '>.' and '><' as tokens first and not allowing ranges with floating point numbers anyway.)

By the way, Python has three 'group' notations: [] for a list {} for a dictionary () for a tuple

Very confusing (and one of the reasons I prefer PHP over Python ;-), and I agree with Rasmus that at least here the symbols no longer make clear what is being meant, but I think that just [] for the values in an array is very intuitive because the same symbols are being used to add the index of an array. (But {} from the set notion in mathematics would be fine too, I think).

By the way, don't forget to allow a comma at the end of a list: 1,2,3,

This especially makes sense when the elements are listed each on a seperate line: 1, 2, 3,

Greetings, Jaap

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 :-) - Chris