[RFC] Short list syntax #1849

Closed
wants to merge 1 commit into
from

5 participants

@nikic nikic commented on the diff Apr 7, 2016
Zend/tests/list_001.phpt
@@ -5,6 +5,8 @@
list($a, list($b)) = array(new stdclass, array(new stdclass));
var_dump($a, $b);
+[$a, [$b]] = array(new stdclass, array(new stdclass));
+var_dump($a, $b);
@nikic
nikic added a note Apr 7, 2016

Missing test for error on [42] = ... and similar.

@bwoebi
bwoebi added a note Apr 7, 2016

I've not added many [] tests, it's using the exactly same syntax (array_pair_list) in parser and the differences are abstracted away inside AST.
If there would be a difference, I'd add tests, but here they would be just outright redundant.

@nikic
nikic added a note Apr 7, 2016

You've added eight or so new error conditions and only one of them is currently covered.

I'm asking about [42] = ... specifically because it's something the list() implementation would not necessarily check for (as it already had parser level checks for that).

@bwoebi
bwoebi added a note Apr 7, 2016

Okay, added list_008.phpt

@nikic
nikic added a note Apr 7, 2016

Another case of interest may be [&$a] = ...

Oh, yeah, list() still doesn't support assignment by-reference. I'd wanted to fix that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mindplay-dk

Just wondering, have you thought of this weird edge case?

$a = "a";
$b = "b";

[$foo, $bar] = [$baz, $bat] = [$a, $b];

It's pretty ambigious - kind of hard to even assess what that means or what that would do.

I don't know if there's a real use case where this would ever matter - I just thought of it so figured I'd bring it up in case there's a missing edge test-case or something.

@TazeTSchnitzel

Behaves the same as with list($foo, $bar) = list($baz, $bat) = [$a, $b];

@mindplay-dk

Well, good, but a test-case to prove that fact probably wouldn't hurt? :-)

@laruence
php.net member

can this be closed? @bwoebi

@nikic

Yes, it has already been merged.

@nikic nikic closed this May 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment