Andi Gutmans wrote:

Personally I don't like having two ways of doing things. It makes it harder for people to read scripts.

It looks like the one way of doing two separate things.
I mean that semanics of two usages of square brackets as operator is inverse depending on whether it is used in unary or binary form.


Being unary, square brackets operator is array constructor.
And being applied to left-side variable it becomes a reference to an array element.


These two usages do some sort of inverse stuff.

BTW is [1][0]==1 true with the proposed syntax?

However, I think the proposed syntax is significantly more elegant than today's array() which makes me think twice about the idea and possibly making an exception to the rule. I think it'll improve the look of PHP scripts. Also I think people calling methods using call_user_method([$obj, "method"]); will find it sexier than the array() syntax.
I guess I think it'd be interesting to see what other's think. Also, another point to check is if list() can also be converted into [] because having a hybrid wouldn't be too nice.

That was what I think although I am not the one to listened to.


Andi

At 12:33 AM 11/5/2003 +0100, Christian Schneider wrote:

I propose to add an alternative (backward compatible) short array creation syntax:
$a = [ 1, 2, 3 ]; and $a = [ 'a' => 42, 'b' => "foo" ];


It can also be used in function calls:
img(['src' => "logo.gif", 'alt' => "Logo"]);

Reason behind this change: Arrays are used a lot and should therefore have as little syntactic overhead as possible. And I think the short syntax is also easier to read and write.

A patch for the parser is trivial and is attached for Zend2.

Note: I checked the newsgroup archive but couldn't find a discussion about this. After not hearing back about my proposed enhancement to debug_backtrace() and the dangling comma for function call parameters being rejected I wonder if I'm using the right mailing list for this :-)

- Chris

-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to