1

I don't know if I can ask this question here. I usually mistake, but...

I every want the "array json style" on PHP, like $a = [1, 2, $value];. But I read that PHP developers HATE this idea because too many people wants, and they thought it best not to offer the feature.

The question is: WHY? I thought that might conflict with some existing feature, but I could not think of any.

Additional: someone know what is the PHP dev features list (where it is presented and discussed)?

8
  • 3
    array(1,2,$value) isn't good enough for you? Commented Sep 16, 2011 at 16:31
  • Is there really any problem with just saying $a = array(1, 2, $value);? The only difference is you put array before it and use parenthesis instead of curly braces. Commented Sep 16, 2011 at 16:32
  • This is a really simple example. But if you use keys and multi-dimentional, can be more complex: [1, 2, {3: 4}] vs. array(1, 2, array(3 => 4)) Commented Sep 16, 2011 at 16:33
  • PHP developers HATE this idea because too many people wants ... that does not seem to make sense. The reasons for pro and con are given in the link @Tim provided. Still, I don't think this question is a good fit for SO. Commented Sep 16, 2011 at 16:37
  • Related but obviously outdated question: Does PHP feature short hand syntax for objects? Commented Sep 16, 2011 at 16:38

3 Answers 3

5

There is a possibly that this will be added in PHP 5.4. As you can see, Andrei Zmievski, Andi Gutmans, and Rasmus Lerdorf, all very important people in PHP's development, voted in favour of the new syntax.

You can see all feature requests that are being proposed and voted on here.

Sign up to request clarification or add additional context in comments.

2 Comments

Ah!!! Great! Thanks, is it that I'm search for. :)
Then you read it wrong: wiki.php.net/rfc/objectarrayliterals (found at Tim Cooper's link)
0

PHP does not have this kind of arrays at all (that is - sequences of elements that are indexed with numbers). It would be strange to have a notation for something that does not exist.

Neither has PHP the kind of arrays that - in JSON - look like this: {a:"asd",b:"sdsfsdf"}. That's because what we have in PHP is a mix of the two: an array that is at the same time indexed with integers and with strings. And none od the two notations look convincing (or are acceptable as JSON):

$a = ["a","b", 36=>"test", "name"=>"Filip"];
$b = {"name": "Filip", 36: "test"}

Comments

0

One 'why not', redundant additional syntax.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.