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

David Rodrigues
  • 12,041
  • 16
  • 62
  • 90
  • 3
    `array(1,2,$value)` isn't good enough for you? – zzzzBov Sep 16 '11 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. – Jonathan Kuhn Sep 16 '11 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))` – David Rodrigues Sep 16 '11 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. – Felix Kling Sep 16 '11 at 16:37
  • Related but obviously outdated question: [Does PHP feature short hand syntax for objects?](http://stackoverflow.com/questions/455800/does-php-feature-short-hand-syntax-for-objects) – Gumbo Sep 16 '11 at 16:38
  • haha really... I mean: "PHP developers hate the idea because many people want, and they always have to be refused, and the idea keeps coming back." :p – David Rodrigues Sep 16 '11 at 16:38
  • Keep in mind that with the `{a:0}` syntax, you use an object to emulate the functionality of an associative array; it is however *not* an array. – Jacco Sep 16 '11 at 16:39
  • re: your additional: The developers have a wiki that talk about features for php 5.4 https://wiki.php.net/todo/php54 – rrehbein Sep 16 '11 at 16:39

3 Answers3

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.

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"}
fdreger
  • 12,264
  • 1
  • 36
  • 42
0

One 'why not', redundant additional syntax.

rrehbein
  • 4,120
  • 1
  • 17
  • 23