php-zephir-parser
php-zephir-parser copied to clipboard
[NFR] Support for list()
From @mruz on January 24, 2014 11:43
It would be nice to can use list():
var width, height;
list(width, height) = getimagesize(value["tmp_name"]);
Copied from original issue: phalcon/zephir#105
From @wapmorgan on February 20, 2014 19:52
Agree.
From @lstrojny on February 20, 2014 23:34
Wouldn’t proper destructuring be more desirable?
left, right = getimagesize(...}
From @nkt on February 21, 2014 0:1
@lstrojny :+1: I think there is no o need to add new keyword.
var a, b, c;
let c = [1, 2];
let a, b = c;
From @nkt on September 7, 2014 13:20
So, i've added support in parser for syntax like:
let [a, b, c] = arr;
@phalcon, @ovr, @mruz what do you think about this syntax? I've tried to add support for
let a, b, c = arr;
But failed.
From @ovr on September 7, 2014 13:31
Vote for
let a, b, c = arr;
From @nkt on September 7, 2014 13:33
@ovr I agree with your vote, but do u know how to add this in parser?
From @ovr on September 7, 2014 13:40
@nkt Nope :smile:
From @mruz on September 7, 2014 15:5
let [a, b, c] = arr;
Is enough for me.
From @thaJeztah on September 7, 2014 15:58
I may actually prefer let [a, b, c] = arr.
It may be just me, but I would (at a glance) interpret
let a, b, c = arr
as
let a = arr; let b = arr; let c = arr;
The extra brackets would hint at 'something extra is performed here' when scanning code.
From @phalcon on September 7, 2014 19:49
I'd prefer
let (a, b, c) = arr;
We can use this syntax in the future to assign the same value to every index in the array:
let [0, 1, 2] = null;
From @aschwin on November 26, 2014 15:52
Is there a decision already for this issue?
Just want to add my bit..
Stolen from ECMAScript 6 (JS) : http://es6-features.org/#ArrayMatching
let [item0, , item2] = arr; // => let item0 = arr[0], item[2] = arr;
http://es6-features.org/#ObjectMatchingDeepMatching
let { key1, key2{subkey} } = someObject; // => let key1 = someObject->key1, key2 = someObject->key2->subkey;
let { key1, key2[subIndex] } = someObject; // => let key1 = someObject->key1, key2 = someObject->key2["subIndex"];
That's if you want to reinvent the wheel, then please stay as close as some standardized language.
Otherwise stick as close as PHP as possible (using parenthesis) :
let [a, , c] = arr;
Edit: bracket [] is the new standard of PHP7