Live data from Hacker News

PHP Short Syntax for Arrays: developers say no.

wiki.php.net

1–10 of 89 posts

Re: PHP Short Syntax for Arrays: developers say no.

#5

I've been wanting this for a long time, seems like a no brainer to me. It'd be nice to add some of the nice syntactic sugar that other languages have. Kinda strange that they have both readable and unreadable listed as both pro and con...

I don't think that a concise method of working with arrays should be thought of as syntactic sugar, not if you mean it in a pejorative way.

I found array_map, array_filter, array_key_exists, array_this, array_that painful to write, but never felt that I was gaining any sort of readability for it.

Re: PHP Short Syntax for Arrays: developers say no.

#6

I've been wanting this for a long time, seems like a no brainer to me. It'd be nice to add some of the nice syntactic sugar that other languages have. Kinda strange that they have both readable and unreadable listed as both pro and con...

The pro/cons are arguments extracted from the mailing list. So the guys on the pro side said it was readable, the guys on the contra side said unreadable.

I think it would have been a nice addition...

Re: PHP Short Syntax for Arrays: developers say no.

#7

    $a1 = [1, 2, 3];
    $b1 = ['foo': 'orange', 'bar': 'apple', 'baz': 'lemon'];
    $b2 = ['foo' => 'orange', 'bar' => 'apple', 'baz' => 'lemon'];

    $a1 = array(1, 2, 3);
    $b1 = array('foo' => 'orange', 'bar' => 'apple', 'baz' => 'lemon');
It would be a nice change to have, but the syntax isn't -that- much better. A compromise might be:

    $b1 = array('foo': 'orange', 'bar': 'apple', 'baz': 'lemon');
But even then, you only save two characters per key:value.

Re: PHP Short Syntax for Arrays: developers say no.

#9

I've been wanting this for a long time, seems like a no brainer to me. It'd be nice to add some of the nice syntactic sugar that other languages have. Kinda strange that they have both readable and unreadable listed as both pro and con...

Guess this just means what's readable to one person is not necessarily readable to another.
Post reply on HN