Re: Proposal: Array syntax

From: Date: Wed, 05 Nov 2003 18:29:10 +0000
Subject: Re: Proposal: Array syntax
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-5259@lists.php.net to get a copy of this message
Michael Walter wrote:
$a = [1,2,$b[11]]; Is that confusing enough for you? ;-)
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]);
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.
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.
Actually, no, I don't. I'm not sure what "grouping" and "application" mean... Mt.

« previous php.internals (#5259) next »