# Short syntax for array literals [...]

- Thread: https://externals.io/message/37786
- Original archive: https://news-web.php.net/php.internals/37786
- Started by Stan Vassilev | FM on 2008-05-22T02:12:49+00:00
- Messages: 93
- Page 1 of 4: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/37786.md?page=2
- 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

---

## #37786 — Stan Vassilev | FM — 2008-05-22T02:12:49+00:00

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

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

---

## #37787 — Felipe Pena — 2008-05-22T02:20:49+00:00

URL: https://externals.io/message/37786#37787 · In reply to: #37786

Hello

Em Qui, 2008-05-22 às 05:12 +0300, Stan Vassilev | FM escreveu:
> Was this discussed before on the list?

Yes. 

http://marc.info/?l=php-internals&m=119995972028293&w=2

> 
> Regards, 
> Stan Vassilev 
-- 
Regards,
Felipe Pena.

---

## #37788 — Stanislav Malyshev — 2008-05-22T03:53:42+00:00

URL: https://externals.io/message/37786#37788 · In reply to: #37786

Hi!

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

Proposed twice at least, but PHP developer community doesn't seem to 
like it.

-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #37792 — Pierre Joye — 2008-05-22T09:46:33+00:00

URL: https://externals.io/message/37786#37792 · In reply to: #37788

> Hi!
>
> > […]
>
> Proposed twice at least, but PHP developer community doesn't seem to like
> it.

Many of us like it. And the end users I know like it too.

Cheers,
-- 
Pierre
http://blog.thepimp.net | http://www.libgd.org

---

## #37793 — Antony Dovgal — 2008-05-22T09:56:57+00:00

URL: https://externals.io/message/37786#37793 · In reply to: #37792

> 
> > […]
> 
> Many of us like it. And the end users I know like it too.

I see no advantages here, only another way to do already possible thing and 
yet another way to confuse people.
But starting this discussion from the very beginning makes very little sense.

-- 
Wbr, 
Antony Dovgal

---

## #37795 — Pierre Joye — 2008-05-22T10:33:26+00:00

URL: https://externals.io/message/37786#37795 · In reply to: #37793

> 
> > […]
>
> I see no advantages here, only another way to do already possible thing and
> yet another way to confuse people.
> But starting this discussion from the very beginning makes very little
> sense.

Agreed, we should simply go through a vote and be done with that.


-- 
Pierre
http://blog.thepimp.net | http://www.libgd.org

---

## #37801 — johannes@php.net — 2008-05-22T13:56:29+00:00

URL: https://externals.io/message/37786#37801 · In reply to: #37795

Hi,


> Agreed, we should simply go through a vote and be done with that.

Vote until all are annoyed and don't vote against it anymore just to
stop voting? ("it's less annoying to have it than vote about it every
two months") There was some voting about this feature quite recently,
don't have the archive link at hand.

johannes

---

## #37802 — Pierre Joye — 2008-05-22T14:29:02+00:00

URL: https://externals.io/message/37786#37802 · In reply to: #37801

> Hi,
>
> 
> > […]
>
> Vote until all are annoyed and don't vote against it anymore just to
> stop voting? ("it's less annoying to have it than vote about it every
> two months") There was some voting about this feature quite recently,
> don't have the archive link at hand.

Really? I missed the conclusion then. But if there was one, let begin to count.

-- 
Pierre
http://blog.thepimp.net | http://www.libgd.org

---

## #37804 — Philip Olson — 2008-05-22T15:55:25+00:00

URL: https://externals.io/message/37786#37804 · In reply to: #37802

> On Thu, May 22, 2008 at 3:56 PM, Johannes Schlüter  
> <johannes@php.net> wrote:
> > […]
>
> Really? I missed the conclusion then. But if there was one, let  
> begin to count.

Whether something is concluded or not is in the eye of the beholder...  
but it appears the conclusion here is:

  This is too much [unnecessary] magic:
  - http://php.markmail.org/message/k2xoyx5ql65vj6r6

Regards,
Philip

---

## #37805 — Stanislav Malyshev — 2008-05-22T16:18:07+00:00

URL: https://externals.io/message/37786#37805 · In reply to: #37792

Hi!

> Many of us like it. And the end users I know like it too.

You don't need to convince me :)
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #37815 — Andi Gutmans — 2008-05-23T04:16:14+00:00

URL: https://externals.io/message/37786#37815 · In reply to: #37804

Not sure we really reached a conclusion. I think it was inconclusive and people got tired.

As I've stated in the past in general I don't like the ability to do things in more than one way but in this case I think the advantages of the cleaner syntax outweigh the fact that we'd have two ways. I'd prefer to support [] but I don't think it's a huge deal if we don't do it. It would make PHP a bit nicer :)

Andi

---

## #37816 — Brian Moon — 2008-05-23T04:30:01+00:00

URL: https://externals.io/message/37786#37816 · In reply to: #37815

Andi Gutmans wrote:
> Not sure we really reached a conclusion. I think it was inconclusive and people got tired.
>
> As I've stated in the past in general I don't like the ability to do things in more than one way but in this case I think the advantages of the cleaner syntax outweigh the fact that we'd have two ways. I'd prefer to support [] but I don't think it's a huge deal if we don't do it. It would make PHP a bit nicer :)
>
> Andi

I almost typed it the other day not thinking.  Been doing a lot of YUI 
and {} and [] are growing on me.

+1

-- 

Brian Moon
Senior Developer/Engineer
------------------------------
When you care enough to spend the very least.
http://dealnews.com/

---

## #37819 — Lokrain — 2008-05-23T08:28:47+00:00

URL: https://externals.io/message/37786#37819 · In reply to: #37816

Hello,

-100. This discussion is closed long ago.

---

## #37820 — Pierre Joye — 2008-05-23T08:59:17+00:00

URL: https://externals.io/message/37786#37820 · In reply to: #37816

> Andi Gutmans wrote:
> > […]
>
> I almost typed it the other day not thinking.  Been doing a lot of YUI and
> {} and [] are growing on me.
>
> +1

For the record here, +1.

-- 
Pierre
http://blog.thepimp.net | http://www.libgd.org

---

## #37821 — Alexey Zakhlestin — 2008-05-23T09:06:42+00:00

URL: https://externals.io/message/37786#37821 · In reply to: #37820

> For the record here, +1.

+1 (for informational purposes, do not have karma to actually vote)


-- 
Alexey Zakhlestin
http://blog.milkfarmsoft.com/

---

## #37822 — Jani Taskinen — 2008-05-23T11:45:51+00:00

URL: https://externals.io/message/37786#37822 · In reply to: #37801

Johannes Schlüter wrote:
> Hi,
> 
> 
> > […]
> 
> Vote until all are annoyed and don't vote against it anymore just to
> stop voting? ("it's less annoying to have it than vote about it every
> two months") There was some voting about this feature quite recently,
> don't have the archive link at hand.

I vote for no votes. They're meaningless anyway. Whoever commits first, 
wins. ;)

Pierre: Care to reply to my email (sent to pierre.dev@gmail.com several 
times now..)

--Jani

---

## #37824 — Eric Coleman — 2008-05-23T13:44:20+00:00

URL: https://externals.io/message/37786#37824 · In reply to: #37822

+1


> Johannes Schlüter wrote:
> > […]
>
> I vote for no votes. They're meaningless anyway. Whoever commits first,
> wins. ;)
>
> Pierre: Care to reply to my email (sent to pierre.dev@gmail.com several
> times now..)
>
> --Jani

---

## #37831 — Yi Wang — 2008-05-23T15:18:10+00:00

URL: https://externals.io/message/37786#37831 · In reply to: #37786

I'm not using this syntax. But I don't oppose it.


>
>  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


-- 
Regards,
Wang Yi

---

## #37921 — Sebastian Deutsch — 2008-05-27T20:53:44+00:00

URL: https://externals.io/message/37786#37921 · In reply to: #37786

dont have karma - but I would love it! so +1 here.
would it make sense to write an RFC?

cheers

Sebastian

Stan Vassilev | FM schrieb:
> 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

---

## #37922 — Sebastian Deutsch — 2008-05-27T22:58:24+00:00

URL: https://externals.io/message/37786#37922 · In reply to: #37921

fyi - i added a RFC

http://wiki.php.net/rfc/shortsyntaxforarrays

please add your votes

cheers

Sebastian

Sebastian Deutsch schrieb:
> dont have karma - but I would love it! so +1 here.
> would it make sense to write an RFC?
> 
> cheers
> 
> Sebastian
> 
> Stan Vassilev | FM schrieb:
> > […]

---

## #37923 — Stanislav Malyshev — 2008-05-27T23:10:34+00:00

URL: https://externals.io/message/37786#37923 · In reply to: #37922

> please add your votes

I'm +1.

BTW - how hard would it be to add voting interface to the wiki?
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #37924 — Jani Taskinen — 2008-05-27T23:14:37+00:00

URL: https://externals.io/message/37786#37924 · In reply to: #37923

Stanislav Malyshev kirjoitti:
> > […]
> 
> I'm +1.
> 
> BTW - how hard would it be to add voting interface to the wiki?

For the record: I'm -1. array() is enough.
Ridiculous idea to begin with..and please no more voting, isn't there enough 
spam already?

--Jani

---

## #37925 — Stanislav Malyshev — 2008-05-27T23:18:28+00:00

URL: https://externals.io/message/37786#37925 · In reply to: #37924

Hi!

> Ridiculous idea to begin with..and please no more voting, isn't there 
> enough spam already?

What do you mean "no more voting"?
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #37926 — Sebastian Deutsch — 2008-05-27T23:21:24+00:00

URL: https://externals.io/message/37786#37926 · In reply to: #37815

Andi Gutmans schrieb:
> Not sure we really reached a conclusion. I think it was inconclusive and people got tired.
> 
> As I've stated in the past in general I don't like the ability to do things in more than one way but in this case I think the advantages of the cleaner syntax outweigh the fact that we'd have two ways. I'd prefer to support [] but I don't think it's a huge deal if we don't do it. It would make PHP a bit nicer :)
> 
> Andi
> 
can I take this one as a +1?

Sebastian

---

## #37927 — Rasmus Lerdorf — 2008-05-28T00:27:40+00:00

URL: https://externals.io/message/37786#37927 · In reply to: #37923

Stanislav Malyshev wrote:
> > […]
> 
> I'm +1.

I'm ok with it as well.  Like I said over a year ago (*), it is a syntax 
very familiar to web developers and it feels natural to most people.

(*) http://marc.info/?l=php-internals&m=117060700805108&w=2

-Rasmus

---

Next page: https://externals.io/message/37786.md?page=2
