# Proposal: Array syntax

- Thread: https://externals.io/message/5238
- Original archive: https://news-web.php.net/php.internals/5238
- Started by Ford on 2003-11-05T17:09:33+00:00
- Messages: 8
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #5238 — Ford — 2003-11-05T17:09:33+00:00

URL: https://externals.io/message/5238#5238

On 05 November 2003 17:06, Marco Tabini contributed these pearls of wisdom:

> Christian Schneider wrote:
> > […]
> 
> Besides my previous points, something even more abominable:
> 
> $a = [1,2,$b[11]];
> 
> Is that confusing enough for you? ;-)

What's confusing about it?

Cheers!

Mike

-- 
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211

---

## #5240 — Marco Tabini — 2003-11-05T17:18:31+00:00

URL: https://externals.io/message/5238#5240 · In reply to: #5238

Ford, Mike [LSS] wrote:
> On 05 November 2003 17:06, Marco Tabini contributed these pearls of wisdom:
> 
> 
> > […]
> 
> 
> What's confusing about it?
> 

The fact that $b[11] references an item of an array, while [1,2,$b[11]] 
assigns values to the array $a. The fact that you (and, probably, most 
of us) can't tell right off the bat is a clear sign that this is a bad 
idea, because it's ambiguous and confusing.

The same line using the current syntax, btw, would have looked like this:

$a = array (1,3,$b[11]);

As you can see the ambiguity is gone--square brackets are used for one 
purpose and nothing else.

Cheers,


Marco

---

## #5256 — Michael Walter — 2003-11-05T18:12:32+00:00

URL: https://externals.io/message/5238#5256 · In reply to: #5240

> > […]
> 
> The fact that $b[11] references an item of an array, while [1,2,$b[11]] 
> assigns values to the array $a. The fact that you (and, probably, most 
> of us) can't tell right off the bat is a clear sign that this is a bad 
> idea, because it's ambiguous and confusing.
> 
> The same line using the current syntax, btw, would have looked like this:
> 
> $a = array (1,3,$b[11]);
Actually, $a = [1,2,$b[11]] would be amazingly clear and expressive in 
comparison with the rather verbose array() version (same thing with the 
swap, btw).

BTW, remember the alternative range syntax [a..b] I mentioned before? If 
you consider Markus Boegers (sp?) iterators extension, wouldn't it be 
top cool to have [a..] syntax, too (yielding an iterator)? And have 
versions of map/filter/reduce support iterators, too? :) Well, just 
thinking out loud, you remember ;)

> As you can see the ambiguity is gone--square brackets are used for one 
> purpose and nothing else.
Actually, do you realize that you use () both for "grouping" and for 
application? I can't see anything wrong with using square brackets for 
array element access and array creation, to be honest.

Cheers,
Michael

---

## #5259 — Marco Tabini — 2003-11-05T18:29:10+00:00

URL: https://externals.io/message/5238#5259 · In reply to: #5256

Michael Walter wrote:
> > […]
> 
> Actually, $a = [1,2,$b[11]] would be amazingly clear and expressive in 
> comparison with the rather verbose array() version (same thing with the 
> swap, btw).

I guess we'll have to agree to disagree :)

$a = [1,2,$b[11]] is semantically inconsistent.

> > […]
> 
> Actually, do you realize that you use () both for "grouping" and for 
> application? I can't see anything wrong with using square brackets for 
> array element access and array creation, to be honest.

Actually, no, I don't. I'm not sure what "grouping" and "application" 
mean...


Mt.

---

## #5261 — Michael Walter — 2003-11-05T18:36:10+00:00

URL: https://externals.io/message/5238#5261 · In reply to: #5259

> I guess we'll have to agree to disagree
> $a = [1,2,$b[11]] is semantically inconsistent. 

Yeah, I agree to disagree on that one, too :)

> > […]
> 
> 
> Actually, no, I don't. I'm not sure what "grouping" and "application" 
> mean...

$a*(1+2) vs. $a(1+2)

"Grouping" (not really a good term, I'm sorry) in the sense of 
determining the order of evaluation.

"Application" being normal function application (function call).

Cheers,
Michael

---

## #5264 — George Schlossnagle — 2003-11-05T18:56:40+00:00

URL: https://externals.io/message/5238#5264 · In reply to: #5259

> $a = [1,2,$b[11]] is semantically inconsistent.

How so?  Is

foo(array(1,2));

semantically inconsistent?  On one hand () is used with a language 
construct (array()), whereas in the other context it indicates 
arguments to a function.  I think that is what he meant by 'grouping' 
and 'application'.

Similar tokens have different syntactical meaning all over the 
language.  Compare '<<' and '<<<'.  To me that is no diffent that 
<variable>[] and [].

George (still -1, but because it makes for unmaintainable code, not 
because it's hard to read)

---

## #5266 — Marco Tabini — 2003-11-05T19:11:00+00:00

URL: https://externals.io/message/5238#5266 · In reply to: #5264

George Schlossnagle wrote:
> 
> 
> 
> > […]
> 
> 
> How so?  Is
> 

I think I've already explained why.

> foo(array(1,2));
> 
> semantically inconsistent?  On one hand () is used with a language 
> construct (array()), whereas in the other context it indicates arguments 
> to a function.  I think that is what he meant by 'grouping' and 
> 'application'.
> 

Actually, I think it meant something else. In any case, semantically you 
can still think of array() as a function (until you throw in key 
declarations, of course ;) )

> Similar tokens have different syntactical meaning all over the 
> language.  Compare '<<' and '<<<'.  To me that is no diffent that 
> <variable>[] and [].

Again, that's not a good reason to introduce more.


Mt.

> 
> George (still -1, but because it makes for unmaintainable code, not 
> because it's hard to read)

---

## #5269 — Michael Walter — 2003-11-05T20:26:36+00:00

URL: https://externals.io/message/5238#5269 · In reply to: #5266

Marco Tabini wrote:
> George Schlossnagle wrote:
> 
> > […]
> 
> I think I've already explained why.

Not really understandable, though.

> 
> > […]
> 
> Actually, I think it meant something else. In any case, semantically you 
> can still think of array() as a function (until you throw in key 
> declarations, of course ;) )

Yup, I told you I meant something different (although on the same line 
of reasoning). I think you misunderstand "semantics", anyway. You should 
not think of array() as a function, as basically everything else except 
to the syntax is different to "real" functions, consider 
call_user_func('array', 1, 2, 3) or array_map('array', array(1, 2, 3), 
array("Foo", "Bar", "Baz"));

How much better would look map('array', [1..3], ["Foo", "Bar", "Baz"]); 
anyway.. (although we really should not argue about that, as it's simply 
taste).

> > […]
> 
> 
> Again, that's not a good reason to introduce more.

That is a statement backed up by good argumentation. :)
